Skip to content

Commit

Permalink
Merge pull request #31 from elwyncrestha/feature/user-profile
Browse files Browse the repository at this point in the history
Feature: Added filter for doctor and patient in specification.
  • Loading branch information
elwyncrestha authored Jul 11, 2020
2 parents 244b850 + 4de112d commit 5811691
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
public class DoctorSpec implements Specification<Doctor> {

private static final String FILTER_BY_NAME = "user.name";
private static final String FILTER_BY_USER_ID = "user.id";
public static final String FILTER_BY_DEPARTMENT_ID = "department.id";

private final String property;
Expand All @@ -31,6 +32,8 @@ public Predicate toPredicate(Root<Doctor> root, CriteriaQuery<?> criteriaQuery,
switch (property) {
case FILTER_BY_NAME:
return criteriaBuilder.equal(root.join("user").get("name"), value.toLowerCase());
case FILTER_BY_USER_ID:
return criteriaBuilder.equal(root.join("user").get("id"), Long.valueOf(value));
case FILTER_BY_DEPARTMENT_ID:
return criteriaBuilder.equal(root.join("department").get("id"), Long.valueOf(value));
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
*/
public class PatientSpec implements Specification<Patient> {

private static final String FILTER_BY_USER_ID = "user.id";

private final String property;
private final String value;

Expand All @@ -25,6 +27,11 @@ public PatientSpec(String property, String value) {
@Override
public Predicate toPredicate(Root<Patient> root, CriteriaQuery<?> criteriaQuery,
CriteriaBuilder criteriaBuilder) {
return null;
switch (property) {
case FILTER_BY_USER_ID:
return criteriaBuilder.equal(root.join("user").get("id"), Long.valueOf(value));
default:
return null;
}
}
}

0 comments on commit 5811691

Please sign in to comment.