-
Notifications
You must be signed in to change notification settings - Fork 131
chore: GET /students multiple status filter #764
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: preprod
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -77,13 +77,15 @@ public List<Student> getStudents( | |
| @RequestParam(value = "first_name", required = false, defaultValue = "") String firstName, | ||
| @RequestParam(value = "last_name", required = false, defaultValue = "") String lastName, | ||
| @RequestParam(value = "course_id", required = false, defaultValue = "") String courseId, | ||
| @RequestParam(name = "status", required = false) EnableStatus status, | ||
| @RequestParam(name = "status", required = false, defaultValue = "ENABLED,SUSPENDED") | ||
| List<EnableStatus> status, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. userStatuses
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. param name can be the same for retro-compatibility however you MUST change your variable names |
||
| @RequestParam(name = "sex", required = false) Sex sex, | ||
| @RequestParam(name = "work_study_status", required = false) WorkStudyStatus workStatus, | ||
| @RequestParam(name = "commitment_begin_date", required = false) Instant commitmentBeginDate, | ||
| @RequestParam(name = "exclude_groups", required = false) List<String> excludeGroupIds) { | ||
| User.Sex domainSex = sexEnumMapper.toDomainSexEnum(sex); | ||
| User.Status domainStatus = statusEnumMapper.toDomainStatus(status); | ||
| List<User.Status> domainStatus = | ||
| status == null ? null : status.stream().map(statusEnumMapper::toDomainStatus).toList(); | ||
|
Comment on lines
+87
to
+88
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. handle it in the mapper method, and why you give a default value as ENABLED, SUSPENDED but you handle nullable value here ?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. agreed, also list variables should be named with plural nouns, hence statuses |
||
| return userService | ||
| .getByLinkedCourse( | ||
| STUDENT, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,7 +29,7 @@ public List<User> findByCriteria( | |
| String firstName, | ||
| String lastName, | ||
| Pageable pageable, | ||
| User.Status status, | ||
| List<User.Status> status, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. userStatuses, static import User.Status |
||
| User.Sex sex, | ||
| WorkStudyStatus workStatus, | ||
| Instant commitmentBeginDate, | ||
|
|
@@ -80,7 +80,7 @@ public List<User> findByCriteria( | |
| } | ||
|
|
||
| if (status != null) { | ||
| predicate = builder.and(predicate, builder.equal(root.get("status"), status)); | ||
| predicate = builder.and(predicate, root.get("status").in(status)); | ||
| } | ||
|
|
||
| if (sex != null) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -214,9 +214,10 @@ public List<User> getByCriteria( | |
| User.Sex sex) { | ||
| Pageable pageable = | ||
| PageRequest.of(page.getValue() - 1, pageSize.getValue(), Sort.by(ASC, "ref")); | ||
| List<User.Status> statusList = status == null ? null : List.of(status); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why you handle always the null value. But ok, i'll be fine with it but remember sometimes it's a bad things to use null as value instead it's better to use Optional or List and check if it's empty if a List and check if present if Optional
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if status null, List.of(), else List.of(status) a List object should never be null |
||
|
|
||
| return userManagerDao.findByCriteria( | ||
| role, ref, firstName, lastName, pageable, status, sex, null, null, null, null, null); | ||
| role, ref, firstName, lastName, pageable, statusList, sex, null, null, null, null, null); | ||
| } | ||
|
|
||
| public List<User> getByLinkedCourse( | ||
|
|
@@ -227,7 +228,7 @@ public List<User> getByLinkedCourse( | |
| String courseId, | ||
| PageFromOne page, | ||
| BoundedPageSize pageSize, | ||
| User.Status status, | ||
| List<User.Status> status, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. userStatuses, static import User.Status |
||
| User.Sex sex, | ||
| WorkStudyStatus workStatus, | ||
| Instant commitmentBeginDate, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,7 @@ | |
| import static org.mockito.Mockito.times; | ||
| import static org.mockito.Mockito.verify; | ||
| import static org.mockito.Mockito.when; | ||
| import static school.hei.haapi.endpoint.rest.model.EnableStatus.DISABLED; | ||
| import static school.hei.haapi.endpoint.rest.model.EnableStatus.ENABLED; | ||
| import static school.hei.haapi.endpoint.rest.model.EnableStatus.SUSPENDED; | ||
| import static school.hei.haapi.endpoint.rest.model.PaymentFrequency.MONTHLY; | ||
|
|
@@ -79,7 +80,6 @@ | |
| import school.hei.haapi.endpoint.rest.client.ApiException; | ||
| import school.hei.haapi.endpoint.rest.model.Coordinates; | ||
| import school.hei.haapi.endpoint.rest.model.CrupdateStudent; | ||
| import school.hei.haapi.endpoint.rest.model.EnableStatus; | ||
| import school.hei.haapi.endpoint.rest.model.Fee; | ||
| import school.hei.haapi.endpoint.rest.model.Group; | ||
| import school.hei.haapi.endpoint.rest.model.Statistics; | ||
|
|
@@ -271,7 +271,7 @@ public static Student disabledStudent1() { | |
| .lastName("One") | ||
| .email("test+disable1@hei.school") | ||
| .ref("STD29001") | ||
| .status(EnableStatus.DISABLED) | ||
| .status(DISABLED) | ||
| .sex(M) | ||
| .birthDate(LocalDate.parse("2000-12-01")) | ||
| .entranceDatetime(Instant.parse("2021-11-08T08:25:24.00Z")) | ||
|
|
@@ -498,8 +498,7 @@ void manager_read_by_disabled_status_ok() throws ApiException { | |
| UsersApi api = new UsersApi(manager1Client); | ||
|
|
||
| List<Student> actualStudents = | ||
| api.getStudents( | ||
| 1, 10, null, null, null, null, EnableStatus.DISABLED, null, null, null, null); | ||
| api.getStudents(1, 10, null, null, null, null, List.of(DISABLED), null, null, null, null); | ||
| assertEquals(2, actualStudents.size()); | ||
| assertTrue(actualStudents.contains(disabledStudent1())); | ||
| } | ||
|
|
@@ -511,7 +510,7 @@ void manager_read_by_suspended_status_ok() throws ApiException { | |
| UsersApi api = new UsersApi(manager1Client); | ||
|
|
||
| List<Student> actualStudents = | ||
| api.getStudents(1, 10, null, null, null, null, SUSPENDED, null, null, null, null); | ||
| api.getStudents(1, 10, null, null, null, null, List.of(SUSPENDED), null, null, null, null); | ||
| assertEquals(1, actualStudents.size()); | ||
| assertTrue(actualStudents.contains(suspendedStudent1())); | ||
| } | ||
|
|
@@ -535,7 +534,7 @@ void manager_read_by_status_and_sex_ok() throws ApiException { | |
| UsersApi api = new UsersApi(manager1Client); | ||
|
|
||
| List<Student> actualStudents = | ||
| api.getStudents(1, 10, null, null, null, null, EnableStatus.DISABLED, F, null, null, null); | ||
| api.getStudents(1, 10, null, null, null, null, List.of(DISABLED), F, null, null, null); | ||
| assertEquals(1, actualStudents.size()); | ||
| } | ||
|
|
||
|
|
@@ -988,7 +987,8 @@ void manager_write_suspended_student() throws ApiException { | |
| List<Student> actual = api.createOrUpdateStudents(List.of(creatableSuspendedStudent()), null); | ||
| Student created = actual.get(0); | ||
| List<Student> suspended = | ||
| api.getStudents(1, 10, null, "Suspended", null, null, SUSPENDED, null, null, null, null); | ||
| api.getStudents( | ||
| 1, 10, null, "Suspended", null, null, List.of(SUSPENDED), null, null, null, null); | ||
|
|
||
| assertTrue(suspended.contains(created)); | ||
| assertEquals(1, actual.size()); | ||
|
|
@@ -1004,7 +1004,7 @@ void manager_update_student_to_suspended() throws ApiException { | |
| api.createOrUpdateStudents(List.of(createStudent2().status(SUSPENDED)), null); | ||
| Student updated = actual.getFirst(); | ||
| List<Student> suspended = | ||
| api.getStudents(1, 10, null, null, null, null, SUSPENDED, null, null, null, null); | ||
| api.getStudents(1, 10, null, null, null, null, List.of(SUSPENDED), null, null, null, null); | ||
|
|
||
| assertTrue(suspended.contains(updated)); | ||
| assertEquals(1, actual.size()); | ||
|
|
@@ -1016,11 +1016,50 @@ void stats_are_exact() throws ApiException { | |
| UsersApi usersApi = new UsersApi(manager1Client); | ||
|
|
||
| Integer women = | ||
| usersApi.getStudents(1, 200, null, null, null, null, null, F, null, null, null).size(); | ||
| usersApi | ||
| .getStudents( | ||
| 1, | ||
| 200, | ||
| null, | ||
| null, | ||
| null, | ||
| null, | ||
| List.of(SUSPENDED, ENABLED, DISABLED), | ||
| F, | ||
| null, | ||
| null, | ||
| null) | ||
| .size(); | ||
| Integer men = | ||
| usersApi.getStudents(1, 200, null, null, null, null, null, M, null, null, null).size(); | ||
| usersApi | ||
| .getStudents( | ||
| 1, | ||
| 200, | ||
| null, | ||
| null, | ||
| null, | ||
| null, | ||
| List.of(SUSPENDED, ENABLED, DISABLED), | ||
| M, | ||
| null, | ||
| null, | ||
| null) | ||
| .size(); | ||
| Integer totalStudents = | ||
| usersApi.getStudents(1, 200, null, null, null, null, null, null, null, null, null).size(); | ||
| usersApi | ||
| .getStudents( | ||
| 1, | ||
| 200, | ||
| null, | ||
| null, | ||
| null, | ||
| null, | ||
| List.of(SUSPENDED, ENABLED, DISABLED), | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. and where you check Student with only two status ? |
||
| null, | ||
| null, | ||
| null, | ||
| null) | ||
| .size(); | ||
|
|
||
| Statistics statistics = usersApi.getStats(); | ||
| assertEquals(statistics.getWomen().getTotal(), women); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's time to rename this variable. And use a better name like UserStatus or StudentStatus, EnableStatus means only ENABLE as status no ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agreed, however it will be a breaking change