Finding a person now definitely only returns a single result.
This commit is contained in:
parent
e7d4683970
commit
058de81acd
@ -103,7 +103,7 @@ class Controller {
|
|||||||
entries = newObservation.entries,
|
entries = newObservation.entries,
|
||||||
tutors = tutors,
|
tutors = tutors,
|
||||||
persons = newObservation.persons.asSequence().map {
|
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()
|
}.toSet()
|
||||||
)
|
)
|
||||||
observation = observationRepository.save(observation)
|
observation = observationRepository.save(observation)
|
||||||
@ -133,7 +133,7 @@ class Controller {
|
|||||||
}
|
}
|
||||||
}.orElse(listOf())
|
}.orElse(listOf())
|
||||||
} else if (observationsRequest.person != null && observationsRequest.person.isNotEmpty() && observationsRequest.site != null) {
|
} 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()
|
val site = siteRepository.findById(observationsRequest.site).get()
|
||||||
return if (observationsRequest.whom == null || observationsRequest.whom.isEmpty())
|
return if (observationsRequest.whom == null || observationsRequest.whom.isEmpty())
|
||||||
observationRepository.findBySiteAndPersonsAndDateBetween(site, person, observationsRequest.startDate, observationsRequest.endDate)
|
observationRepository.findBySiteAndPersonsAndDateBetween(site, person, observationsRequest.startDate, observationsRequest.endDate)
|
||||||
|
@ -29,5 +29,5 @@ interface ObservationRepository : CrudRepository<Observation, Long> {
|
|||||||
@Repository
|
@Repository
|
||||||
interface PersonRepository : CrudRepository<Person, Long> {
|
interface PersonRepository : CrudRepository<Person, Long> {
|
||||||
|
|
||||||
fun findByName(name: String): Person?
|
fun findFirstByNameLike(name: String): Person?
|
||||||
}
|
}
|
@ -186,7 +186,7 @@ class ControllerTest {
|
|||||||
control = 4.0, conservatism = 3.0, teamworkCommunications = 2.0, teamworkLeadership = 3.0,
|
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))
|
teamworkWorkload = 1.0, knowledge = 1.0, entries = listOf(), tutors = setOf(tutor), persons = setOf(person))
|
||||||
doReturn(Optional.of(site)).`when`(siteRepository).findById(1)
|
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())
|
doReturn(listOf(observation)).`when`(observationRepository).findBySiteAndPersonsAndDateBetween(site, person, LocalDate.now(), LocalDate.now())
|
||||||
val result = controller.getObservations(request)
|
val result = controller.getObservations(request)
|
||||||
assertEquals(1, result.size)
|
assertEquals(1, result.size)
|
||||||
|
@ -613,7 +613,7 @@ class RepositoryTest {
|
|||||||
fun testFindPersonByName() {
|
fun testFindPersonByName() {
|
||||||
val person = entityManager.persist(Person(name = "Foo Bar"))
|
val person = entityManager.persist(Person(name = "Foo Bar"))
|
||||||
entityManager.persist(person)
|
entityManager.persist(person)
|
||||||
val result = personRepository.findByName("Foo Bar")
|
val result = personRepository.findFirstByNameLike("Foo Bar")
|
||||||
assertEquals(person, result)
|
assertEquals(person, result)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -621,14 +621,14 @@ class RepositoryTest {
|
|||||||
fun testFindPersonByName_IncorrectName() {
|
fun testFindPersonByName_IncorrectName() {
|
||||||
val person = entityManager.persist(Person(name = "Foo Bar"))
|
val person = entityManager.persist(Person(name = "Foo Bar"))
|
||||||
entityManager.persist(person)
|
entityManager.persist(person)
|
||||||
val result = personRepository.findByName("Foo")
|
val result = personRepository.findFirstByNameLike("Foo")
|
||||||
assertNotSame(person, result)
|
assertNotSame(person, result)
|
||||||
assertNull(result)
|
assertNull(result)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testFindPersonByName_NoPersons() {
|
fun testFindPersonByName_NoPersons() {
|
||||||
val result = personRepository.findByName("Foo")
|
val result = personRepository.findFirstByNameLike("Foo")
|
||||||
assertNull(result)
|
assertNull(result)
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user