From d54db4aa92b96eadab8bea08988b85e00517ecbe Mon Sep 17 00:00:00 2001 From: Nathan Cannon Date: Thu, 1 Nov 2018 10:13:44 +0000 Subject: [PATCH] Searches for whom is now case insensitive. --- .../co/neviyn/observationdatabase/Controller.kt | 6 +++--- .../co/neviyn/observationdatabase/Repository.kt | 6 +++--- .../neviyn/observationdatabase/ControllerTest.kt | 4 ++-- .../neviyn/observationdatabase/RepositoryTest.kt | 16 ++++++++-------- 4 files changed, 16 insertions(+), 16 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 9f09564..d9ed4cd 100644 --- a/backend/src/main/kotlin/uk/co/neviyn/observationdatabase/Controller.kt +++ b/backend/src/main/kotlin/uk/co/neviyn/observationdatabase/Controller.kt @@ -126,7 +126,7 @@ class Controller { (observationsRequest.whom == null || observationsRequest.whom.isEmpty()) -> observationRepository.findByTutorsAndDateBetween(tutor = it, startDate = observationsRequest.startDate, endDate = observationsRequest.endDate) - else -> observationRepository.findByTutorsAndWhomAndDateBetween(tutor = it, + else -> observationRepository.findByTutorsAndWhomIgnoreCaseAndDateBetween(tutor = it, whom = observationsRequest.whom, startDate = observationsRequest.startDate, endDate = observationsRequest.endDate) @@ -138,14 +138,14 @@ class Controller { return if (observationsRequest.whom == null || observationsRequest.whom.isEmpty()) observationRepository.findBySiteAndPersonsAndDateBetween(site, person, observationsRequest.startDate, observationsRequest.endDate) else - observationRepository.findBySiteAndWhomAndPersonsAndDateBetween(site, observationsRequest.whom, person, observationsRequest.startDate, observationsRequest.endDate) + observationRepository.findBySiteAndWhomIgnoreCaseAndPersonsAndDateBetween(site, observationsRequest.whom, person, observationsRequest.startDate, observationsRequest.endDate) } else if (observationsRequest.site != null) { return siteRepository.findById(observationsRequest.site).map { when { (observationsRequest.whom == null || observationsRequest.whom.isEmpty()) -> observationRepository.findBySiteAndDateBetween(site = it, startDate = observationsRequest.startDate, endDate = observationsRequest.endDate) - else -> observationRepository.findBySiteAndWhomAndDateBetween(site = it, + else -> observationRepository.findBySiteAndWhomIgnoreCaseAndDateBetween(site = it, whom = observationsRequest.whom, startDate = observationsRequest.startDate, endDate = observationsRequest.endDate) 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 b06f03f..02e4d09 100644 --- a/backend/src/main/kotlin/uk/co/neviyn/observationdatabase/Repository.kt +++ b/backend/src/main/kotlin/uk/co/neviyn/observationdatabase/Repository.kt @@ -17,13 +17,13 @@ interface ObservationRepository : CrudRepository { fun findByTutorsAndDateBetween(tutor: Tutor, startDate: LocalDate, endDate: LocalDate): List - fun findBySiteAndWhomAndDateBetween(site: Site, whom: String, startDate: LocalDate, endDate: LocalDate): List + fun findBySiteAndWhomIgnoreCaseAndDateBetween(site: Site, whom: String, startDate: LocalDate, endDate: LocalDate): List - fun findByTutorsAndWhomAndDateBetween(tutor: Tutor, whom: String, startDate: LocalDate, endDate: LocalDate): List + fun findByTutorsAndWhomIgnoreCaseAndDateBetween(tutor: Tutor, whom: String, startDate: LocalDate, endDate: LocalDate): List fun findBySiteAndPersonsAndDateBetween(site: Site, person: Person, startDate: LocalDate, endDate: LocalDate): List - fun findBySiteAndWhomAndPersonsAndDateBetween(site: Site, whom: String, person: Person, startDate: LocalDate, endDate: LocalDate): List + fun findBySiteAndWhomIgnoreCaseAndPersonsAndDateBetween(site: Site, whom: String, person: Person, startDate: LocalDate, endDate: LocalDate): List } @Repository 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 1b516c8..06cd0ae 100644 --- a/backend/src/test/kotlin/uk/co/neviyn/observationdatabase/ControllerTest.kt +++ b/backend/src/test/kotlin/uk/co/neviyn/observationdatabase/ControllerTest.kt @@ -135,7 +135,7 @@ class ControllerTest { teamworkWorkload = 1.0, knowledge = 1.0, entries = listOf(), tutors = setOf(), persons = setOf()) doReturn(Optional.of(site)).`when`(siteRepository).findById(1) doReturn(listOf(observation)) - .`when`(observationRepository).findBySiteAndWhomAndDateBetween(site, "Group A", LocalDate.now(), LocalDate.now()) + .`when`(observationRepository).findBySiteAndWhomIgnoreCaseAndDateBetween(site, "Group A", LocalDate.now(), LocalDate.now()) val result = controller.getObservations(request) assertEquals(1, result.size) assertEquals(observation, result[0]) @@ -169,7 +169,7 @@ class ControllerTest { teamworkWorkload = 1.0, knowledge = 1.0, entries = listOf(), tutors = setOf(tutor), persons = setOf()) doReturn(Optional.of(tutor)).`when`(tutorRepository).findById(1) doReturn(listOf(observation)) - .`when`(observationRepository).findByTutorsAndWhomAndDateBetween(tutor, "Group A", LocalDate.now(), LocalDate.now()) + .`when`(observationRepository).findByTutorsAndWhomIgnoreCaseAndDateBetween(tutor, "Group A", LocalDate.now(), LocalDate.now()) val result = controller.getObservations(request) assertEquals(1, result.size) assertEquals(observation, result[0]) diff --git a/backend/src/test/kotlin/uk/co/neviyn/observationdatabase/RepositoryTest.kt b/backend/src/test/kotlin/uk/co/neviyn/observationdatabase/RepositoryTest.kt index 85fb76a..4ac6132 100644 --- a/backend/src/test/kotlin/uk/co/neviyn/observationdatabase/RepositoryTest.kt +++ b/backend/src/test/kotlin/uk/co/neviyn/observationdatabase/RepositoryTest.kt @@ -32,8 +32,8 @@ class RepositoryTest { } @Test - fun testFindBySiteAndWhomAndDateBetween_EmptyRepository() { - val result = observationRepository.findBySiteAndWhomAndDateBetween(Site( + fun testFindBySiteAndWhomIgnoreCaseAndDateBetween_EmptyRepository() { + val result = observationRepository.findBySiteAndWhomIgnoreCaseAndDateBetween(Site( id = 1, name = "x" ), "none", LocalDate.now(), LocalDate.now()) @@ -51,8 +51,8 @@ class RepositoryTest { } @Test - fun testFindByTutorsAndWhomAndDateBetween_EmptyRepository() { - val result = observationRepository.findByTutorsAndWhomAndDateBetween(Tutor( + fun testFindByTutorsAndWhomIgnoreCaseAndDateBetween_EmptyRepository() { + val result = observationRepository.findByTutorsAndWhomIgnoreCaseAndDateBetween(Tutor( id = 1, name = "x", site = Site(1, "x") @@ -153,7 +153,7 @@ class RepositoryTest { } @Test - fun testFindBySiteAndWhomAndDateBetween() { + fun testFindBySiteAndWhomIgnoreCaseAndDateBetween() { val correctSite = entityManager.persist(Site(name = "Correct")) val incorrectSite = entityManager.persist(Site(name = "Incorrect")) val person = entityManager.persist(Person(name = "Foo Bar")) @@ -254,7 +254,7 @@ class RepositoryTest { entityManager.persist(wrongSite) entityManager.persist(justRight) entityManager.persist(wrongWhom) - val result = observationRepository.findBySiteAndWhomAndDateBetween( + val result = observationRepository.findBySiteAndWhomIgnoreCaseAndDateBetween( site = correctSite, startDate = LocalDate.now().minusDays(1), endDate = LocalDate.now().plusDays(1), @@ -381,7 +381,7 @@ class RepositoryTest { } @Test - fun testFindByTutorsAndWhomAndDateBetween() { + fun testFindByTutorsAndWhomIgnoreCaseAndDateBetween() { val site = entityManager.persist(Site(name = "Correct")) val person = entityManager.persist(Person(name = "Foo Bar")) val correctTutor = entityManager.persist(Tutor(name = "X", site = site)) @@ -504,7 +504,7 @@ class RepositoryTest { entityManager.persist(correctTutor) incorrectTutor.observations.addAll(listOf(wrongTutor, justRightMultipleTutors)) entityManager.persist(incorrectTutor) - val result = observationRepository.findByTutorsAndWhomAndDateBetween( + val result = observationRepository.findByTutorsAndWhomIgnoreCaseAndDateBetween( tutor = correctTutor, startDate = LocalDate.now().minusDays(1), endDate = LocalDate.now().plusDays(1),