diff --git a/backend/app/src/main/java/com/ugent/pidgeon/controllers/CourseController.java b/backend/app/src/main/java/com/ugent/pidgeon/controllers/CourseController.java index 8a171c56..15218a66 100644 --- a/backend/app/src/main/java/com/ugent/pidgeon/controllers/CourseController.java +++ b/backend/app/src/main/java/com/ugent/pidgeon/controllers/CourseController.java @@ -56,7 +56,7 @@ public class CourseController { */ @GetMapping(ApiRoutes.COURSE_BASE_PATH) @Roles({UserRole.teacher, UserRole.student}) - public ResponseEntity getUserCourses(Auth auth, @RequestParam(value="archived", required = false) Boolean archived) { + public ResponseEntity getUserCourses(Auth auth, @RequestParam(value = "archived", required = false) Boolean archived) { long userID = auth.getUserEntity().getId(); try { Logger.getGlobal().info("Archived: " + archived); @@ -111,7 +111,7 @@ public ResponseEntity createCourse(@RequestBody CourseJson courseJson, Auth a } // Create new course - CourseEntity courseEntity = new CourseEntity(courseJson.getName(), courseJson.getDescription()); + CourseEntity courseEntity = new CourseEntity(courseJson.getName(), courseJson.getDescription(), courseJson.getYear()); // Get current time and convert to SQL Timestamp OffsetDateTime currentTimestamp = OffsetDateTime.now(); courseEntity.setCreatedAt(currentTimestamp); @@ -143,6 +143,7 @@ private ResponseEntity doCourseUpdate(CourseEntity courseEntity, CourseJson c } courseEntity.setName(courseJson.getName()); courseEntity.setDescription(courseJson.getDescription()); + courseEntity.setCourseYear(courseJson.getYear()); if (courseJson.getArchived() != null) { courseEntity.setArchivedAt(courseJson.getArchived() ? OffsetDateTime.now() : null); } @@ -191,8 +192,8 @@ public ResponseEntity patchCourse(@RequestBody CourseJson courseJson, @PathVa return ResponseEntity.status(checkResult.getStatus()).body(checkResult.getMessage()); } - if (courseJson.getName() == null && courseJson.getDescription() == null) { - return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Name or description is required"); + if (courseJson.getName() == null && courseJson.getDescription() == null && courseJson.getYear() == null) { + return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Name, description or year is required"); } CourseEntity courseEntity = checkResult.getData(); @@ -202,6 +203,9 @@ public ResponseEntity patchCourse(@RequestBody CourseJson courseJson, @PathVa if (courseJson.getDescription() == null) { courseJson.setDescription(courseEntity.getDescription()); } + if (courseJson.getYear() == null) { + courseJson.setYear(courseEntity.getCourseYear()); + } return doCourseUpdate(courseEntity, courseJson, user); } catch (Exception e) { @@ -234,7 +238,6 @@ public ResponseEntity getCourseByCourseId(@PathVariable long courseId, Auth a } - /** * Function to delete a course by its ID * @@ -319,7 +322,7 @@ public ResponseEntity getProjectsByCourseId(@PathVariable Long courseId, Auth if (relation.equals(CourseRelation.enrolled)) { projects = projects.stream().filter(ProjectEntity::isVisible).toList(); } - List projectResponseJsons = projects.stream().map(projectEntity -> + List projectResponseJsons = projects.stream().map(projectEntity -> entityToJsonConverter.projectEntityToProjectResponseJson(projectEntity, course, user) ).toList(); @@ -340,7 +343,7 @@ private ResponseEntity getJoinLinkPostResponseEntity(long courseId, String co return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Failed to add user to individual group, contact admin."); } courseUserRepository.save(new CourseUserEntity(courseId, user.getId(), CourseRelation.enrolled)); - return ResponseEntity.ok(entityToJsonConverter.courseEntityToCourseWithInfo(course, courseUtil.getJoinLink(course.getJoinKey(),"" + course.getId()), false)); + return ResponseEntity.ok(entityToJsonConverter.courseEntityToCourseWithInfo(course, courseUtil.getJoinLink(course.getJoinKey(), "" + course.getId()), false)); } private ResponseEntity getJoinLinkGetResponseEntity(long courseId, String courseKey, UserEntity user) { @@ -360,8 +363,8 @@ private ResponseEntity getJoinLinkGetResponseEntity(long courseId, String cou /** * Function to join course with key * - * @param auth authentication object of the requesting user - * @param courseId ID of the course to join + * @param auth authentication object of the requesting user + * @param courseId ID of the course to join * @param courseKey key of the course to join * @return ResponseEntity with a statuscode and no body * @ApiDog apiDog documentation @@ -378,8 +381,8 @@ public ResponseEntity joinCourse(Auth auth, @PathVariable Long courseId, @Pat /** * Function to get course information for joining course with key * - * @param auth authentication object of the requesting user - * @param courseId ID of the course to get the join key from + * @param auth authentication object of the requesting user + * @param courseId ID of the course to get the join key from * @param courseKey key of the course to get the join key from * @return ResponseEntity with a statuscode and a JSON object containing the course information * @ApiDog apiDog documentation @@ -396,7 +399,7 @@ public ResponseEntity getCourseJoinKey(Auth auth, @PathVariable Long courseId /** * Function to join course without key * - * @param auth authentication object of the requesting user + * @param auth authentication object of the requesting user * @param courseId ID of the course to join * @return ResponseEntity with a statuscode and no body * @ApiDog apiDog documentation @@ -413,7 +416,7 @@ public ResponseEntity joinCourse(Auth auth, @PathVariable Long courseId) { /** * Function to get course information for joining course without key * - * @param auth authentication object of the requesting user + * @param auth authentication object of the requesting user * @param courseId ID of the course to get the join key from * @return ResponseEntity with a statuscode and a JSON object containing the course information * @ApiDog apiDog documentation @@ -431,7 +434,7 @@ public ResponseEntity getCourseJoinKey(Auth auth, @PathVariable Long courseId * Function to leave a course * * @param courseId ID of the course to leave - * @param auth authentication object of the requesting user + * @param auth authentication object of the requesting user * @return ResponseEntity with a statuscode and no body * @ApiDog apiDog documentation * @HttpMethod DELETE @@ -466,9 +469,9 @@ public ResponseEntity leaveCourse(@PathVariable long courseId, Auth auth) { /** * Function to remove a different user from a course * - * @param auth authentication object of the requesting user + * @param auth authentication object of the requesting user * @param courseId ID of the course to leave - * @param userId JSON object containing the user id + * @param userId JSON object containing the user id * @return ResponseEntity with a statuscode and no body * @ApiDog apiDog documentation * @HttpMethod DELETE @@ -496,9 +499,9 @@ public ResponseEntity removeCourseMember(Auth auth, @PathVariable Long course /** * Function to add a different user to a course * - * @param auth authentication object of the requesting user + * @param auth authentication object of the requesting user * @param courseId ID of the course to add the user to - * @param request JSON object containing the user id and relation + * @param request JSON object containing the user id and relation * @return ResponseEntity with a statuscode and no body * @ApiDog apiDog documentation * @HttpMethod POST @@ -531,9 +534,9 @@ public ResponseEntity addCourseMember(Auth auth, @PathVariable Long courseId, /** * Function to update the relation of a user in a course * - * @param auth authentication object of the requesting user + * @param auth authentication object of the requesting user * @param courseId ID of the course to update the user in - * @param request JSON object containing the user id and relation + * @param request JSON object containing the user id and relation * @return ResponseEntity with a statuscode and no body * @ApiDog apiDog documentation * @HttpMethod PATCH @@ -577,7 +580,7 @@ public ResponseEntity updateCourseMember(Auth auth, @PathVariable Long course /** * Function to get all members of a course * - * @param auth authentication object of the requesting user + * @param auth authentication object of the requesting user * @param courseId ID of the course to get the members from * @return ResponseEntity with a JSON object containing the members of the course * @ApiDog apiDog documentation @@ -610,7 +613,7 @@ public ResponseEntity getCourseMembers(Auth auth, @PathVariable Long courseId /** * Function to get the join link of a course * - * @param auth authentication object of the requesting user + * @param auth authentication object of the requesting user * @param courseId ID of the course to get the join link from * @return ResponseEntity with the join link of the course * @ApiDog apiDog documentation @@ -629,10 +632,11 @@ public ResponseEntity getCourseKey(Auth auth, @PathVariable Long courseI } // Function for invalidating the previous key and generating a new one, can be useful when starting a new year. + /** * Function to generate a new join link for a course * - * @param auth authentication object of the requesting user + * @param auth authentication object of the requesting user * @param courseId ID of the course to generate the join link for * @return ResponseEntity with the new join link of the course * @ApiDog apiDog documentation @@ -658,7 +662,7 @@ public ResponseEntity getAndGenerateCourseKey(Auth auth, @PathVariable Long c /** * Function to remove the joinKey from the joinLink of a course * - * @param auth authentication object of the requesting user + * @param auth authentication object of the requesting user * @param courseId ID of the course to remove the join link from * @return ResponseEntity with the new join link of the course (without the key) * @ApiDog apiDog documentation @@ -679,4 +683,5 @@ public ResponseEntity deleteCourseKey(Auth auth, @PathVariable Long cour return ResponseEntity.ok(""); } + } \ No newline at end of file diff --git a/backend/app/src/main/java/com/ugent/pidgeon/model/json/CourseJson.java b/backend/app/src/main/java/com/ugent/pidgeon/model/json/CourseJson.java index d9e99c49..ad7674f8 100644 --- a/backend/app/src/main/java/com/ugent/pidgeon/model/json/CourseJson.java +++ b/backend/app/src/main/java/com/ugent/pidgeon/model/json/CourseJson.java @@ -8,10 +8,13 @@ public class CourseJson{ private Boolean isArchived; - public CourseJson(String name, String description, Boolean isArchived) { + private Integer year; + + public CourseJson(String name, String description, Boolean isArchived, Integer courseYear) { this.name = name; this.description = description; this.isArchived = isArchived; + this.year = courseYear; } public String getName() { @@ -37,5 +40,13 @@ public Boolean getArchived() { public void setArchived(Boolean isArchived) { this.isArchived = isArchived; } + + public Integer getYear() { + return year; + } + + public void setYear(Integer courseYear) { + this.year = courseYear; + } } diff --git a/backend/app/src/main/java/com/ugent/pidgeon/model/json/CourseWithInfoJson.java b/backend/app/src/main/java/com/ugent/pidgeon/model/json/CourseWithInfoJson.java index 0ba3cef9..d7464a18 100644 --- a/backend/app/src/main/java/com/ugent/pidgeon/model/json/CourseWithInfoJson.java +++ b/backend/app/src/main/java/com/ugent/pidgeon/model/json/CourseWithInfoJson.java @@ -13,6 +13,7 @@ public record CourseWithInfoJson ( String joinUrl, String joinKey, OffsetDateTime archivedAt, - OffsetDateTime createdAt + OffsetDateTime createdAt, + Integer year ) {} diff --git a/backend/app/src/main/java/com/ugent/pidgeon/model/json/CourseWithRelationJson.java b/backend/app/src/main/java/com/ugent/pidgeon/model/json/CourseWithRelationJson.java index 4882e9e5..9f52dca6 100644 --- a/backend/app/src/main/java/com/ugent/pidgeon/model/json/CourseWithRelationJson.java +++ b/backend/app/src/main/java/com/ugent/pidgeon/model/json/CourseWithRelationJson.java @@ -4,5 +4,5 @@ import java.time.OffsetDateTime; public record CourseWithRelationJson (String url, CourseRelation relation, String name, Long courseId, - OffsetDateTime archivedAt, Integer memberCount, OffsetDateTime createdAt) { } + OffsetDateTime archivedAt, Integer memberCount, OffsetDateTime createdAt, Integer year) { } diff --git a/backend/app/src/main/java/com/ugent/pidgeon/postgre/models/CourseEntity.java b/backend/app/src/main/java/com/ugent/pidgeon/postgre/models/CourseEntity.java index 5ae72f32..042f9d6d 100644 --- a/backend/app/src/main/java/com/ugent/pidgeon/postgre/models/CourseEntity.java +++ b/backend/app/src/main/java/com/ugent/pidgeon/postgre/models/CourseEntity.java @@ -18,6 +18,10 @@ public class CourseEntity { @Column(name = "description", nullable=false) private String description; + @Column(name = "course_year", nullable = true) + private Integer courseYear; + + @Column(name = "created_at") private OffsetDateTime createdAt; @@ -35,9 +39,10 @@ public void setJoinKey(String joinKey) { @Column(name = "join_key", nullable=true) private String joinKey; - public CourseEntity(String name, String description) { + public CourseEntity(String name, String description,Integer courseYear) { this.name = name; this.description = description; + this.courseYear = courseYear; } public CourseEntity() { @@ -71,6 +76,7 @@ public void setDescription(String description) { } + public OffsetDateTime getCreatedAt() { return createdAt; } @@ -86,4 +92,14 @@ public OffsetDateTime getArchivedAt() { public void setArchivedAt(OffsetDateTime archivedAt) { this.archivedAt = archivedAt; } + + public int getCourseYear() { + return courseYear; + } + public void setCourseYear(int courseYear){ + this.courseYear = courseYear; + } + + + } diff --git a/backend/app/src/main/java/com/ugent/pidgeon/util/CourseUtil.java b/backend/app/src/main/java/com/ugent/pidgeon/util/CourseUtil.java index 5ee912f2..c73c16a1 100644 --- a/backend/app/src/main/java/com/ugent/pidgeon/util/CourseUtil.java +++ b/backend/app/src/main/java/com/ugent/pidgeon/util/CourseUtil.java @@ -6,6 +6,7 @@ import com.ugent.pidgeon.postgre.models.types.CourseRelation; import com.ugent.pidgeon.postgre.models.types.UserRole; import com.ugent.pidgeon.postgre.repository.*; +import java.util.logging.Logger; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpMethod; import org.springframework.http.HttpStatus; @@ -260,8 +261,9 @@ public CheckResult checkCourseJson(CourseJson courseJson, UserEntity user, } - if (courseJson.getName() == null || courseJson.getDescription() == null) { - return new CheckResult<>(HttpStatus.BAD_REQUEST, "name and description are required", null); + if (courseJson.getName() == null || courseJson.getDescription() == null || courseJson.getYear() == null) { + Logger.getGlobal().info(""+ courseJson.getYear()); + return new CheckResult<>(HttpStatus.BAD_REQUEST, "name, description and year are required", null); } if (courseJson.getName().isBlank()) { diff --git a/backend/app/src/main/java/com/ugent/pidgeon/util/EntityToJsonConverter.java b/backend/app/src/main/java/com/ugent/pidgeon/util/EntityToJsonConverter.java index 604a3f7d..9056821a 100644 --- a/backend/app/src/main/java/com/ugent/pidgeon/util/EntityToJsonConverter.java +++ b/backend/app/src/main/java/com/ugent/pidgeon/util/EntityToJsonConverter.java @@ -96,7 +96,8 @@ public CourseWithInfoJson courseEntityToCourseWithInfo(CourseEntity course, Stri hideKey ? null : joinLink, hideKey ? null : course.getJoinKey(), course.getArchivedAt(), - course.getCreatedAt() + course.getCreatedAt(), + course.getCourseYear() ); } @@ -109,7 +110,8 @@ public CourseWithRelationJson courseEntityToCourseWithRelation(CourseEntity cour course.getId(), course.getArchivedAt(), memberCount, - course.getCreatedAt() + course.getCreatedAt(), + course.getCourseYear() ); } diff --git a/backend/app/src/test/java/com/ugent/pidgeon/controllers/ClusterControllerTest.java b/backend/app/src/test/java/com/ugent/pidgeon/controllers/ClusterControllerTest.java index 90182e61..24446585 100644 --- a/backend/app/src/test/java/com/ugent/pidgeon/controllers/ClusterControllerTest.java +++ b/backend/app/src/test/java/com/ugent/pidgeon/controllers/ClusterControllerTest.java @@ -63,7 +63,7 @@ public void setup() { })) .build(); - courseEntity = new CourseEntity("name", "description"); + courseEntity = new CourseEntity("name", "description",2024); groupClusterEntity = new GroupClusterEntity(1L, 20, "clustername", 5); groupEntity = new GroupEntity("groupName", 1L); } diff --git a/backend/app/src/test/java/com/ugent/pidgeon/controllers/CourseControllerTest.java b/backend/app/src/test/java/com/ugent/pidgeon/controllers/CourseControllerTest.java index 24b18fc1..9e1e05d5 100644 --- a/backend/app/src/test/java/com/ugent/pidgeon/controllers/CourseControllerTest.java +++ b/backend/app/src/test/java/com/ugent/pidgeon/controllers/CourseControllerTest.java @@ -112,7 +112,7 @@ public String getName() { @Test public void testCreateCourse() throws Exception { - String courseJson = "{\"name\": \"test\", \"description\": \"description\"}"; + String courseJson = "{\"name\": \"test\", \"description\": \"description\",\"courseYear\" : 2024}"; when(courseUtil.checkCourseJson(any(), any(), any())).thenReturn(new CheckResult<>(HttpStatus.OK, "", null)); when(courseRepository.save(any())).thenReturn(null); when(courseUserRepository.save(any())).thenReturn(null); @@ -120,7 +120,7 @@ public void testCreateCourse() throws Exception { when(courseUtil.getJoinLink(any(), any())).thenReturn(""); when(entityToJsonConverter.courseEntityToCourseWithInfo(any(), any(), anyBoolean())). thenReturn(new CourseWithInfoJson(0L, "", "", new UserReferenceJson("", "", 0L), - new ArrayList<>(), "", "", "", OffsetDateTime.now(), OffsetDateTime.now())); + new ArrayList<>(), "", "", "", OffsetDateTime.now(), OffsetDateTime.now(), 2013)); mockMvc.perform(MockMvcRequestBuilders.post(ApiRoutes.COURSE_BASE_PATH) .contentType(MediaType.APPLICATION_JSON) @@ -144,7 +144,7 @@ public void testCreateCourse() throws Exception { // This function also tests all lines of doCourseUpdate @Test public void testUpdateCourse() throws Exception { - String courseJson = "{\"name\": \"test\", \"description\": \"description\"}"; + String courseJson = "{\"name\": \"test\", \"description\": \"description\",\"courseYear\" : 2024}"; when(courseUtil.getCourseIfAdmin(anyLong(), any())). thenReturn(new CheckResult<>(HttpStatus.OK, "", new CourseEntity())); when(courseUtil.checkCourseJson(any(), any(), any())).thenReturn(new CheckResult<>(HttpStatus.OK, "", null)); @@ -176,7 +176,8 @@ public void testUpdateCourse() throws Exception { @Test public void testPatchCourse() throws Exception { String courseJson = "{\"name\": null, \"description\": \"description\"}"; - when(courseUtil.getCourseIfAdmin(anyLong(), any())).thenReturn(new CheckResult<>(HttpStatus.OK, "", new CourseEntity())); + CourseEntity courseEntity = new CourseEntity("name", "description",2024); + when(courseUtil.getCourseIfAdmin(anyLong(), any())).thenReturn(new CheckResult<>(HttpStatus.OK, "", courseEntity)); when(courseUtil.checkCourseJson(any(), any(), any())).thenReturn(new CheckResult<>(HttpStatus.OK, "", null)); when(courseRepository.save(any())).thenReturn(null); @@ -217,7 +218,7 @@ public void testGetCourseByCourseId() throws Exception { when(courseUtil.getJoinLink(any(), any())).thenReturn(""); when(entityToJsonConverter.courseEntityToCourseWithInfo(any(), any(), anyBoolean())). thenReturn(new CourseWithInfoJson(0L, "", "", new UserReferenceJson("", "", 0L), - new ArrayList<>(), "", "", "", OffsetDateTime.now(), OffsetDateTime.now())); + new ArrayList<>(), "", "", "", OffsetDateTime.now(), OffsetDateTime.now(), 2023)); when(courseUtil.getCourseIfUserInCourse(anyLong(), any(UserEntity.class))). thenReturn(new CheckResult<>(HttpStatus.OK, "", new Pair<>(new CourseEntity(), CourseRelation.course_admin))); mockMvc.perform(MockMvcRequestBuilders.get(ApiRoutes.COURSE_BASE_PATH + "/1")) @@ -270,7 +271,7 @@ public void testDeleteCourse() throws Exception { @Test public void testGetProjectsByCourseId() throws Exception { - CourseEntity course = new CourseEntity("name", "descripton"); + CourseEntity course = new CourseEntity("name", "descripton",2024); course.setId(1); List projects = Arrays.asList(new ProjectEntity(), new ProjectEntity()); when(courseUtil.getCourseIfUserInCourse(anyLong(), any())) @@ -301,7 +302,7 @@ public void testGetProjectsByCourseId() throws Exception { @Test public void testJoinCourse() throws Exception { - CourseEntity course = new CourseEntity("name", "descripton"); + CourseEntity course = new CourseEntity("name", "descripton",2024); course.setId(1); when(courseUtil.checkJoinLink(anyLong(), any(), any())).thenReturn(new CheckResult<>(HttpStatus.OK, "", course)); when(commonDatabaseActions.createNewIndividualClusterGroup(anyLong(), any())).thenReturn(true); @@ -320,7 +321,7 @@ public void testJoinCourse() throws Exception { @Test public void testGetJoinKey() throws Exception { - CourseEntity course = new CourseEntity("name", "descripton"); + CourseEntity course = new CourseEntity("name", "descripton",2024); course.setId(1); when(courseUtil.checkJoinLink(anyLong(), any(), any())).thenReturn(new CheckResult<>(HttpStatus.OK, "", course)); mockMvc.perform(MockMvcRequestBuilders.get(ApiRoutes.COURSE_BASE_PATH + "/1/join/1908")) @@ -333,7 +334,7 @@ public void testGetJoinKey() throws Exception { @Test public void testJoinCourseNoKey() throws Exception { - CourseEntity course = new CourseEntity("name", "descripton"); + CourseEntity course = new CourseEntity("name", "descripton",2024); course.setId(1); when(courseUtil.checkJoinLink(anyLong(), any(), any())).thenReturn(new CheckResult<>(HttpStatus.OK, "", course)); when(commonDatabaseActions.createNewIndividualClusterGroup(anyLong(), any())).thenReturn(true); @@ -347,7 +348,7 @@ public void testJoinCourseNoKey() throws Exception { @Test public void testGetCourseJoinKeyNoKey() throws Exception { - CourseEntity course = new CourseEntity("name", "descripton"); + CourseEntity course = new CourseEntity("name", "descripton",2024); course.setId(1); when(courseUtil.checkJoinLink(anyLong(), any(), any())).thenReturn(new CheckResult<>(HttpStatus.OK, "", course)); mockMvc.perform(MockMvcRequestBuilders.get(ApiRoutes.COURSE_BASE_PATH + "/1/join")) @@ -456,7 +457,7 @@ public void testUpdateCourseMember() throws Exception { @Test public void testGetCourseMembers() throws Exception { - CourseEntity course = new CourseEntity("name", "descripton"); + CourseEntity course = new CourseEntity("name", "descripton",2024); course.setId(1); when(courseUtil.getCourseIfUserInCourse(anyLong(), any())). thenReturn(new CheckResult<>(HttpStatus.OK, "", new Pair<>(course, CourseRelation.course_admin))); @@ -474,7 +475,7 @@ public void testGetCourseMembers() throws Exception { @Test public void testGetCourseKey() throws Exception { - CourseEntity course = new CourseEntity("name", "descripton"); + CourseEntity course = new CourseEntity("name", "descripton",2024); course.setId(1); when(courseUtil.getCourseIfAdmin(anyLong(), any())).thenReturn(new CheckResult<>(HttpStatus.OK, "", course)); mockMvc.perform(MockMvcRequestBuilders.get(ApiRoutes.COURSE_BASE_PATH + "/1/joinKey")) @@ -487,7 +488,7 @@ public void testGetCourseKey() throws Exception { @Test public void testGetAndCreateCourseKey() throws Exception { - CourseEntity course = new CourseEntity("name", "descripton"); + CourseEntity course = new CourseEntity("name", "descripton",2024); course.setId(1); when(courseUtil.getCourseIfAdmin(anyLong(), any())).thenReturn(new CheckResult<>(HttpStatus.OK, "", course)); mockMvc.perform(MockMvcRequestBuilders.put(ApiRoutes.COURSE_BASE_PATH + "/1/joinKey")) @@ -500,7 +501,7 @@ public void testGetAndCreateCourseKey() throws Exception { @Test public void testDeleteCourseKey() throws Exception { - CourseEntity course = new CourseEntity("name", "descripton"); + CourseEntity course = new CourseEntity("name", "descripton",2024); course.setId(1); when(courseUtil.getCourseIfAdmin(anyLong(), any())).thenReturn(new CheckResult<>(HttpStatus.OK, "", course)); mockMvc.perform(MockMvcRequestBuilders.delete(ApiRoutes.COURSE_BASE_PATH + "/1/joinKey")) diff --git a/backend/app/src/test/java/com/ugent/pidgeon/postgre/models/CourseEntityTest.java b/backend/app/src/test/java/com/ugent/pidgeon/postgre/models/CourseEntityTest.java index 741bc9c5..c8a4c93f 100644 --- a/backend/app/src/test/java/com/ugent/pidgeon/postgre/models/CourseEntityTest.java +++ b/backend/app/src/test/java/com/ugent/pidgeon/postgre/models/CourseEntityTest.java @@ -55,7 +55,7 @@ public void testJoinKey() { public void testConstructor() { String name = "Test Course"; String description = "Test Description"; - CourseEntity course = new CourseEntity(name, description); + CourseEntity course = new CourseEntity(name, description,2024); assertEquals(name, course.getName()); assertEquals(description, course.getDescription()); } diff --git a/backend/app/src/test/java/com/ugent/pidgeon/util/CourseUtilTest.java b/backend/app/src/test/java/com/ugent/pidgeon/util/CourseUtilTest.java index c25c31f1..b2f5ca09 100644 --- a/backend/app/src/test/java/com/ugent/pidgeon/util/CourseUtilTest.java +++ b/backend/app/src/test/java/com/ugent/pidgeon/util/CourseUtilTest.java @@ -48,7 +48,7 @@ public class CourseUtilTest { public void setUp() { user = new UserEntity("name", "surname", "email", UserRole.student, "azureid"); user.setId(1L); - course = new CourseEntity("name", "description"); + course = new CourseEntity("name", "description",2024); course.setId(1L); course.setJoinKey("key"); cuEnrolled = new CourseUserEntity(1L, 1L, CourseRelation.enrolled); @@ -141,14 +141,14 @@ public void testCheckJoinLink() throws Exception { @Test public void testCheckCourseJson() throws Exception { - CourseJson courseJson = new CourseJson("name", "description", null); + CourseJson courseJson = new CourseJson("name", "description", null,2023); CheckResult result = courseUtil.checkCourseJson(courseJson, user, null); assertEquals(HttpStatus.OK, result.getStatus()); courseJson.setDescription(null); result = courseUtil.checkCourseJson(courseJson, user, null); assertEquals(HttpStatus.BAD_REQUEST, result.getStatus()); - assertEquals("name and description are required", result.getMessage()); + assertEquals("name, description and year are required", result.getMessage()); courseJson.setDescription("description"); courseJson.setName(""); diff --git a/backend/app/src/test/java/com/ugent/pidgeon/util/EntityToJsonConverterTest.java b/backend/app/src/test/java/com/ugent/pidgeon/util/EntityToJsonConverterTest.java index 3b5b9897..b199d564 100644 --- a/backend/app/src/test/java/com/ugent/pidgeon/util/EntityToJsonConverterTest.java +++ b/backend/app/src/test/java/com/ugent/pidgeon/util/EntityToJsonConverterTest.java @@ -76,6 +76,7 @@ public void setUp() { courseEntity = new CourseEntity(); courseEntity.setId(1L); courseEntity.setName("Test Course"); + courseEntity.setCourseYear(2024); projectEntity = new ProjectEntity(); projectEntity.setId(1L); diff --git a/backend/database/populate_database.sql b/backend/database/populate_database.sql index 28ff6cd6..9adfb6e0 100644 --- a/backend/database/populate_database.sql +++ b/backend/database/populate_database.sql @@ -10,12 +10,12 @@ INSERT INTO users (name, surname, email, azure_id, role) VALUES ('Charlie', 'Davis', 'charlie.davis@example.com', 'token_5', 'teacher'); -- Inserting into `courses` -INSERT INTO courses (course_id,course_name, description) VALUES - (1,'Math 101', 'Introduction to Mathematics'), - (2,'Science 101', 'Basics of Scientific Method'), - (3,'History 101', 'World History Overview'), - (4,'Computer Science 101', 'Introduction to Computing'), - (5,'English 101', 'English Literature'); +INSERT INTO courses (course_id,course_name, description, course_year) VALUES + (1,'Math 101', 'Introduction to Mathematics',2023), + (2,'Science 101', 'Basics of Scientific Method',2023), + (3,'History 101', 'World History Overview',2023), + (4,'Computer Science 101', 'Introduction to Computing',2023), + (5,'English 101', 'English Literature',2023); -- Inserting into `course_users` -- Assume course_id and user_id start from 1 and match accordingly diff --git a/backend/database/start_database.sql b/backend/database/start_database.sql index 80a9b0a5..1e076839 100644 --- a/backend/database/start_database.sql +++ b/backend/database/start_database.sql @@ -17,6 +17,7 @@ CREATE TABLE courses ( course_id SERIAL PRIMARY KEY, course_name VARCHAR(100) NOT NULL, description TEXT, + course_year INTEGER, created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP, archived_at TIMESTAMP WITH TIME ZONE DEFAULT NULL, join_key TEXT diff --git a/gha b/gha new file mode 100644 index 00000000..e69de29b