From 8a6e3a312a7df50c543032027d3d8c5c09943764 Mon Sep 17 00:00:00 2001 From: Nathan Cannon Date: Mon, 29 Oct 2018 15:26:12 +0000 Subject: [PATCH] Fixed searching for an observation by an associated individual. --- .../kotlin/uk/co/neviyn/observationdatabase/Controller.kt | 8 +++----- .../kotlin/uk/co/neviyn/observationdatabase/Repository.kt | 1 - .../uk/co/neviyn/observationdatabase/ControllerTest.kt | 2 +- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/backend/src/main/kotlin/uk/co/neviyn/observationdatabase/Controller.kt b/backend/src/main/kotlin/uk/co/neviyn/observationdatabase/Controller.kt index 181423f..7d6f95e 100644 --- a/backend/src/main/kotlin/uk/co/neviyn/observationdatabase/Controller.kt +++ b/backend/src/main/kotlin/uk/co/neviyn/observationdatabase/Controller.kt @@ -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, diff --git a/backend/src/main/kotlin/uk/co/neviyn/observationdatabase/Repository.kt b/backend/src/main/kotlin/uk/co/neviyn/observationdatabase/Repository.kt index 66b3255..fcd8124 100644 --- a/backend/src/main/kotlin/uk/co/neviyn/observationdatabase/Repository.kt +++ b/backend/src/main/kotlin/uk/co/neviyn/observationdatabase/Repository.kt @@ -28,5 +28,4 @@ interface ObservationRepository : CrudRepository { interface PersonRepository : CrudRepository { fun findByName(name: String): Person? - } \ No newline at end of file diff --git a/backend/src/test/kotlin/uk/co/neviyn/observationdatabase/ControllerTest.kt b/backend/src/test/kotlin/uk/co/neviyn/observationdatabase/ControllerTest.kt index 517f994..1b516c8 100644 --- a/backend/src/test/kotlin/uk/co/neviyn/observationdatabase/ControllerTest.kt +++ b/backend/src/test/kotlin/uk/co/neviyn/observationdatabase/ControllerTest.kt @@ -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)