From 5faecc46fe420702a921965b980d46c4bed9e9df Mon Sep 17 00:00:00 2001 From: tendryAxel Date: Fri, 30 May 2025 12:46:00 +0300 Subject: [PATCH 1/4] feat: Group::getStudentGradeAtInstant --- src/main/java/school/hei/haapi/model/Group.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/main/java/school/hei/haapi/model/Group.java b/src/main/java/school/hei/haapi/model/Group.java index 97954a344f..a0aab4f222 100644 --- a/src/main/java/school/hei/haapi/model/Group.java +++ b/src/main/java/school/hei/haapi/model/Group.java @@ -12,6 +12,8 @@ import jakarta.persistence.Table; import java.io.Serializable; import java.time.Instant; +import java.time.LocalDate; +import java.time.Period; import java.util.List; import java.util.Objects; import lombok.AllArgsConstructor; @@ -22,6 +24,7 @@ import lombok.ToString; import org.hibernate.Hibernate; import org.hibernate.annotations.CreationTimestamp; +import school.hei.haapi.model.fee.StudentGrade; @Entity @Table(name = "\"group\"") @@ -86,4 +89,18 @@ public boolean equals(Object o) { public int hashCode() { return getClass().hashCode(); } + + public StudentGrade getStudentGradeAtInstant(LocalDate localDate) { + int promotionYearAge = + Period.between(LocalDate.from(this.getPromotion().getStartDatetime()), localDate).getYears(); + return switch (promotionYearAge) { + case 0 -> StudentGrade.L1; + case 1 -> StudentGrade.L2; + case 2 -> StudentGrade.L3; + default -> + throw new IllegalArgumentException( + "Invalid promotion at instant '%s': the group with ID '%s' cannot have a valid promotion for year %d at this time" + .formatted(localDate, this.id, promotionYearAge)); + }; + } } From 7577e1116b5d9a51a7607e54aeacca1a254b3d1d Mon Sep 17 00:00:00 2001 From: tendryAxel Date: Fri, 30 May 2025 16:25:38 +0300 Subject: [PATCH 2/4] feat: filter student grades by academic year level --- doc/api.yml | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/doc/api.yml b/doc/api.yml index fe105e24c8..0ba2943683 100644 --- a/doc/api.yml +++ b/doc/api.yml @@ -442,22 +442,10 @@ paths: summary: Get student grades. operationId: getStudentGrades parameters: - - name: student_id - in: path - required: true - schema: - type: string - - name: page - in: query - schema: - $ref: '#/components/schemas/Page' - description: Set value to 1 by default if null is provided - required: false - - name: page_size - in: query - description: Set value to 15 by default if null is provided - schema: - $ref: '#/components/schemas/PageSize' + - $ref: '#/components/parameters/PathStudentId' + - $ref: '#/components/schemas/Page' + - $ref: '#/components/schemas/PageSize' + - $ref: '#/components/parameters/AcademicYearLevel' responses: '200': description: List of a student's grades, showing the exam and the course of these grades. @@ -5913,6 +5901,13 @@ components: description: Filter by student first name or last name schema: type: string + AcademicYearLevel: + name: academic_year_level + in: query + required: false + description: Filter by group academic year level + schema: + type: string PathExamId: name: exams_id in: path From 1e76794a8fe2dbe43c29bdaa6f56ee9348a27f9a Mon Sep 17 00:00:00 2001 From: tendryAxel Date: Fri, 30 May 2025 16:26:55 +0300 Subject: [PATCH 3/4] chore: static import --- src/main/java/school/hei/haapi/model/Group.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/main/java/school/hei/haapi/model/Group.java b/src/main/java/school/hei/haapi/model/Group.java index a0aab4f222..4ec089bb6d 100644 --- a/src/main/java/school/hei/haapi/model/Group.java +++ b/src/main/java/school/hei/haapi/model/Group.java @@ -2,6 +2,9 @@ import static jakarta.persistence.FetchType.LAZY; import static jakarta.persistence.GenerationType.IDENTITY; +import static school.hei.haapi.model.fee.StudentGrade.L1; +import static school.hei.haapi.model.fee.StudentGrade.L2; +import static school.hei.haapi.model.fee.StudentGrade.L3; import jakarta.persistence.Entity; import jakarta.persistence.GeneratedValue; @@ -92,11 +95,12 @@ public int hashCode() { public StudentGrade getStudentGradeAtInstant(LocalDate localDate) { int promotionYearAge = - Period.between(LocalDate.from(this.getPromotion().getStartDatetime()), localDate).getYears(); + Period.between(LocalDate.from(this.getPromotion().getStartDatetime()), localDate) + .getYears(); return switch (promotionYearAge) { - case 0 -> StudentGrade.L1; - case 1 -> StudentGrade.L2; - case 2 -> StudentGrade.L3; + case 0 -> L1; + case 1 -> L2; + case 2 -> L3; default -> throw new IllegalArgumentException( "Invalid promotion at instant '%s': the group with ID '%s' cannot have a valid promotion for year %d at this time" From 3205ea763af9c89d982345d30364451a605b7329 Mon Sep 17 00:00:00 2001 From: tendryAxel Date: Fri, 30 May 2025 16:32:42 +0300 Subject: [PATCH 4/4] chore: wrong param in doc --- doc/api.yml | 17 +++++++++++++++-- .../school/hei/haapi/integration/GradeIT.java | 8 ++++---- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/doc/api.yml b/doc/api.yml index 0ba2943683..a1e385e642 100644 --- a/doc/api.yml +++ b/doc/api.yml @@ -443,8 +443,17 @@ paths: operationId: getStudentGrades parameters: - $ref: '#/components/parameters/PathStudentId' - - $ref: '#/components/schemas/Page' - - $ref: '#/components/schemas/PageSize' + - name: page + in: query + schema: + $ref: '#/components/schemas/Page' + description: Set value to 1 by default if null is provided + required: false + - name: page_size + in: query + description: Set value to 15 by default if null is provided + schema: + $ref: '#/components/schemas/PageSize' - $ref: '#/components/parameters/AcademicYearLevel' responses: '200': @@ -5908,6 +5917,10 @@ components: description: Filter by group academic year level schema: type: string + enum: + - L1 + - L2 + - L3 PathExamId: name: exams_id in: path diff --git a/src/test/java/school/hei/haapi/integration/GradeIT.java b/src/test/java/school/hei/haapi/integration/GradeIT.java index 4fa148f3bb..9dd5885483 100644 --- a/src/test/java/school/hei/haapi/integration/GradeIT.java +++ b/src/test/java/school/hei/haapi/integration/GradeIT.java @@ -77,7 +77,7 @@ void manager_read_ok() throws ApiException { TeachingApi api = new TeachingApi(manager1Client); List actualAwardedCourseExamGradesId = - api.getStudentGrades(STUDENT1_ID, 1, 10).stream() + api.getStudentGrades(STUDENT1_ID, 1, 10, null).stream() .map(AwardedCourseExam::getId) .collect(toUnmodifiableList()); @@ -91,7 +91,7 @@ void teacher_read_ok() throws ApiException { ApiClient teacher1Client = anApiClient(TEACHER1_TOKEN); TeachingApi api = new TeachingApi(teacher1Client); - List actual = api.getStudentGrades(STUDENT1_ID, 1, 10); + List actual = api.getStudentGrades(STUDENT1_ID, 1, 10, null); assertTrue(actual.contains(awardedCourseExam1())); assertTrue(actual.contains(awardedCourseExam2())); @@ -104,7 +104,7 @@ void student_read_his_grade_ok() throws ApiException { TeachingApi api = new TeachingApi(student1Client); List actualIds = - api.getStudentGrades(STUDENT1_ID, 1, 10).stream() + api.getStudentGrades(STUDENT1_ID, 1, 10, null).stream() .map(AwardedCourseExam::getId) .collect(toUnmodifiableList()); @@ -117,7 +117,7 @@ void student_read_his_grade_ok() throws ApiException { void student_read_other_grade_ko() { ApiClient student1Client = anApiClient(STUDENT1_TOKEN); TeachingApi api = new TeachingApi(student1Client); - assertThrowsForbiddenException(() -> api.getStudentGrades(STUDENT2_ID, 1, 10)); + assertThrowsForbiddenException(() -> api.getStudentGrades(STUDENT2_ID, 1, 10, null)); assertThrowsForbiddenException(() -> api.getParticipantGrade(GROUP1_ID, EXAM1_ID)); }