I am using @Query annotation for getting documents between specified dates.
@Query("{'admission_date': {$gte: ?0, $lte: ?1}}")
public List<Patient> findByAdmissionDateBetween(String minDate, String maxDate)
Sample Document:
_id: 1015
patientName: "Hemant Srivastav"
gender: "male"
date_of_birth: 2006-07-18T18:30:00.000+00:00
admission_date: 2022-07-01T18:30:00.000+00:00
diagnosis: "broken arm"
but I am getting an exception:
{
"errorMessage": "Patients between dates not found.",
"errorCode": 400
}
My Service and Controller method implementation is this.
Controller:
@GetMapping("/admissiondates")
public ResponseEntity<List<Patient>> getPatientsBtwnAdmissionDates(
@RequestParam @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) String minDate,
@RequestParam @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) String maxDate)
throws PatientAdmissionException {
List<Patient>patientsBtwnDatesList = patientService.getPatientsBtwnAdmissionDates(minDate,maxDate);
return new ResponseEntity<>(patientsBtwnDatesList, HttpStatus.OK);
}
Service:
public List<Patient> getPatientsBtwnAdmissionDates(String minDate, String maxDate)
throws PatientAdmissionException {
List<Patient> patientBtwnDatesList = patientRepository.getPatientsBtwnAdmissionDates(minDate, maxDate);
if (patientBtwnDatesList.isEmpty() == true) {
throw new PatientAdmissionException("Patients between dates not found.");
}
return patientBtwnDatesList;
}
I am not able to understand what mistake am I making pls HELP!