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 d9ed4cd..756fc4d 100644 --- a/backend/src/main/kotlin/uk/co/neviyn/observationdatabase/Controller.kt +++ b/backend/src/main/kotlin/uk/co/neviyn/observationdatabase/Controller.kt @@ -103,7 +103,7 @@ class Controller { entries = newObservation.entries, tutors = tutors, persons = newObservation.persons.asSequence().map { - personRepository.findByName(it.toUpperCase()) ?: personRepository.save(Person(name = it.toUpperCase())) + personRepository.findFirstByNameLike(it.toUpperCase()) ?: personRepository.save(Person(name = it.toUpperCase())) }.toSet() ) observation = observationRepository.save(observation) @@ -133,7 +133,7 @@ class Controller { } }.orElse(listOf()) } else if (observationsRequest.person != null && observationsRequest.person.isNotEmpty() && observationsRequest.site != null) { - val person = personRepository.findByName(observationsRequest.person.toUpperCase()) ?: return listOf() + val person = personRepository.findFirstByNameLike(observationsRequest.person.toUpperCase()) ?: return listOf() val site = siteRepository.findById(observationsRequest.site).get() return if (observationsRequest.whom == null || observationsRequest.whom.isEmpty()) observationRepository.findBySiteAndPersonsAndDateBetween(site, person, observationsRequest.startDate, 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 02e4d09..ef80fcf 100644 --- a/backend/src/main/kotlin/uk/co/neviyn/observationdatabase/Repository.kt +++ b/backend/src/main/kotlin/uk/co/neviyn/observationdatabase/Repository.kt @@ -29,5 +29,5 @@ interface ObservationRepository : CrudRepository { @Repository interface PersonRepository : CrudRepository { - fun findByName(name: String): Person? + fun findFirstByNameLike(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 06cd0ae..5f2b3a9 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).findFirstByNameLike("FOO BAR") doReturn(listOf(observation)).`when`(observationRepository).findBySiteAndPersonsAndDateBetween(site, person, LocalDate.now(), LocalDate.now()) val result = controller.getObservations(request) assertEquals(1, result.size) 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 4ac6132..27abfa4 100644 --- a/backend/src/test/kotlin/uk/co/neviyn/observationdatabase/RepositoryTest.kt +++ b/backend/src/test/kotlin/uk/co/neviyn/observationdatabase/RepositoryTest.kt @@ -613,7 +613,7 @@ class RepositoryTest { fun testFindPersonByName() { val person = entityManager.persist(Person(name = "Foo Bar")) entityManager.persist(person) - val result = personRepository.findByName("Foo Bar") + val result = personRepository.findFirstByNameLike("Foo Bar") assertEquals(person, result) } @@ -621,14 +621,14 @@ class RepositoryTest { fun testFindPersonByName_IncorrectName() { val person = entityManager.persist(Person(name = "Foo Bar")) entityManager.persist(person) - val result = personRepository.findByName("Foo") + val result = personRepository.findFirstByNameLike("Foo") assertNotSame(person, result) assertNull(result) } @Test fun testFindPersonByName_NoPersons() { - val result = personRepository.findByName("Foo") + val result = personRepository.findFirstByNameLike("Foo") assertNull(result) } } \ No newline at end of file