use of io.undertree.symptom.exceptions.NotFoundException in project spring-boot-jpa by ssherwood.
the class PatientRepositoryTests method test_PatientRepository_findByPatientId_ExpectExists.
@Test
public void test_PatientRepository_findByPatientId_ExpectExists() throws Exception {
Patient patient = entityManager.persistFlushFind(new TestPatientBuilder().build());
Patient aPatient = patientRepository.findByPatientId(patient.getPatientId()).orElseThrow(NotFoundException::new);
assertThat(aPatient).isEqualTo(patient);
}
use of io.undertree.symptom.exceptions.NotFoundException in project spring-boot-jpa by ssherwood.
the class PatientController method getPatientsByExample.
/**
* Returns a "paged" collection of resources matching the input query params using default
* matching rules for strings of "contains and ignores case".
* <p>
* TODO I'm not exactly happy with the resource name "queryByExample". Need to research more what
* other APIs look like for this kind of functionality
*
* @param paramMap a Map of fields to use to search with
* @param pageable a Pageable to restrict results
* @return A paged result of matching Patients
*/
@GetMapping("/search/by-example")
public Page<Patient> getPatientsByExample(@RequestParam Map<String, Object> paramMap, @PageableDefault(size = DEFAULT_PAGE_SZ) Pageable pageable) {
// naively copies map entries to matching properties in the Patient POJO
Patient examplePatient = this.jacksonObjectMapper.convertValue(paramMap, Patient.class);
Page<Patient> pagedResults = this.patientRepository.findAll(Example.of(examplePatient, DEFAULT_MATCHER), pageable);
if (!pagedResults.hasContent()) {
throw new NotFoundException(Patient.RESOURCE_PATH, "No Patients found matching example query " + examplePatient);
}
return pagedResults;
}
Aggregations