Fixed searching for an observation by an associated individual.
This commit is contained in:
parent
2834010c3b
commit
8a6e3a312a
@ -132,13 +132,11 @@ class Controller {
|
||||
endDate = observationsRequest.endDate)
|
||||
}
|
||||
}.orElse(listOf())
|
||||
}
|
||||
else if(observationsRequest.person != null && observationsRequest.person.isNotEmpty() && observationsRequest.site != null) {
|
||||
val person = personRepository.findByName(observationsRequest.person) ?: return listOf()
|
||||
} else if (observationsRequest.person != null && observationsRequest.person.isNotEmpty() && observationsRequest.site != null) {
|
||||
val person = personRepository.findByName(observationsRequest.person.toUpperCase()) ?: return listOf()
|
||||
val site = siteRepository.findById(observationsRequest.site).get()
|
||||
return observationRepository.findBySiteAndPersonsAndDateBetween(site, person, observationsRequest.startDate, observationsRequest.endDate)
|
||||
}
|
||||
else if (observationsRequest.site != null) {
|
||||
} else if (observationsRequest.site != null) {
|
||||
return siteRepository.findById(observationsRequest.site).map {
|
||||
when {
|
||||
(observationsRequest.whom == null || observationsRequest.whom.isEmpty()) -> observationRepository.findBySiteAndDateBetween(site = it,
|
||||
|
@ -28,5 +28,4 @@ interface ObservationRepository : CrudRepository<Observation, Long> {
|
||||
interface PersonRepository : CrudRepository<Person, Long> {
|
||||
|
||||
fun findByName(name: String): Person?
|
||||
|
||||
}
|
@ -186,7 +186,7 @@ class ControllerTest {
|
||||
control = 4.0, conservatism = 3.0, teamworkCommunications = 2.0, teamworkLeadership = 3.0,
|
||||
teamworkWorkload = 1.0, knowledge = 1.0, entries = listOf(), tutors = setOf(tutor), persons = setOf(person))
|
||||
doReturn(Optional.of(site)).`when`(siteRepository).findById(1)
|
||||
doReturn(person).`when`(personRepository).findByName("Foo Bar")
|
||||
doReturn(person).`when`(personRepository).findByName("FOO BAR")
|
||||
doReturn(listOf(observation)).`when`(observationRepository).findBySiteAndPersonsAndDateBetween(site, person, LocalDate.now(), LocalDate.now())
|
||||
val result = controller.getObservations(request)
|
||||
assertEquals(1, result.size)
|
||||
|
Loading…
Reference in New Issue
Block a user