Searches for whom is now case insensitive.
This commit is contained in:
parent
2eefe3c217
commit
d54db4aa92
@ -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)
|
||||
|
@ -17,13 +17,13 @@ interface ObservationRepository : CrudRepository<Observation, Long> {
|
||||
|
||||
fun findByTutorsAndDateBetween(tutor: Tutor, startDate: LocalDate, endDate: LocalDate): List<Observation>
|
||||
|
||||
fun findBySiteAndWhomAndDateBetween(site: Site, whom: String, startDate: LocalDate, endDate: LocalDate): List<Observation>
|
||||
fun findBySiteAndWhomIgnoreCaseAndDateBetween(site: Site, whom: String, startDate: LocalDate, endDate: LocalDate): List<Observation>
|
||||
|
||||
fun findByTutorsAndWhomAndDateBetween(tutor: Tutor, whom: String, startDate: LocalDate, endDate: LocalDate): List<Observation>
|
||||
fun findByTutorsAndWhomIgnoreCaseAndDateBetween(tutor: Tutor, whom: String, startDate: LocalDate, endDate: LocalDate): List<Observation>
|
||||
|
||||
fun findBySiteAndPersonsAndDateBetween(site: Site, person: Person, startDate: LocalDate, endDate: LocalDate): List<Observation>
|
||||
|
||||
fun findBySiteAndWhomAndPersonsAndDateBetween(site: Site, whom: String, person: Person, startDate: LocalDate, endDate: LocalDate): List<Observation>
|
||||
fun findBySiteAndWhomIgnoreCaseAndPersonsAndDateBetween(site: Site, whom: String, person: Person, startDate: LocalDate, endDate: LocalDate): List<Observation>
|
||||
}
|
||||
|
||||
@Repository
|
||||
|
@ -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])
|
||||
|
@ -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),
|
||||
|
Loading…
Reference in New Issue
Block a user