Added check for if person is empty in an observations request.

This commit is contained in:
neviyn 2018-10-22 11:19:58 +01:00
parent 95b40bac3d
commit 563bbd17da

View File

@ -133,7 +133,12 @@ class Controller {
} }
}.orElse(listOf()) }.orElse(listOf())
} }
if (observationsRequest.site != null) { else if(observationsRequest.person != null && observationsRequest.person.isNotEmpty() && observationsRequest.site != null) {
val person = personRepository.findByName(observationsRequest.person) ?: return listOf()
val site = siteRepository.findById(observationsRequest.site).get()
return observationRepository.findBySiteAndPersonsAndDateBetween(site, person, observationsRequest.startDate, observationsRequest.endDate)
}
else if (observationsRequest.site != null) {
return siteRepository.findById(observationsRequest.site).map { return siteRepository.findById(observationsRequest.site).map {
when { when {
(observationsRequest.whom == null || observationsRequest.whom.isEmpty()) -> observationRepository.findBySiteAndDateBetween(site = it, (observationsRequest.whom == null || observationsRequest.whom.isEmpty()) -> observationRepository.findBySiteAndDateBetween(site = it,