Skip to content

Commit

Permalink
Merge pull request #51 from elwyncrestha/feauture/appointment-filter
Browse files Browse the repository at this point in the history
Feature: Added Appointment Filter
  • Loading branch information
elwyncrestha authored Aug 9, 2020
2 parents 76bf5ee + c86b6dd commit e8fc4b8
Showing 1 changed file with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@
public class AppointmentSpec implements Specification<Appointment> {

private static final String FILTER_BY_PATIENT_ID = "patient.id";
private static final String FILTER_BY_PATIENT_NAME = "patient.name";
private static final String FILTER_BY_DOCTOR_NAME = "doctor.name";

private static final String PATIENT = "patient";
private static final String DOCTOR = "doctor";
private static final String USER = "user";
private static final String ID = "id";
private static final String NAME = "name";

private final String property;
private final String value;
Expand All @@ -30,8 +38,15 @@ public Predicate toPredicate(Root<Appointment> root, CriteriaQuery<?> query,
CriteriaBuilder criteriaBuilder) {
switch (property) {
case FILTER_BY_PATIENT_ID:
return criteriaBuilder.equal(root.join("patient").get("id"), Long.valueOf(value));
return criteriaBuilder.equal(root.join(PATIENT).get(ID), Long.valueOf(value));
case FILTER_BY_PATIENT_NAME:
return criteriaBuilder
.like(root.join(PATIENT).join(USER).get(NAME), "%" + value + "%");
case FILTER_BY_DOCTOR_NAME:
return criteriaBuilder
.like(root.join(DOCTOR).join(USER).get(NAME), "%" + value + "%");
default:
return null;
}
return null;
}
}

0 comments on commit e8fc4b8

Please sign in to comment.