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,
|
(observationsRequest.whom == null || observationsRequest.whom.isEmpty()) -> observationRepository.findByTutorsAndDateBetween(tutor = it,
|
||||||
startDate = observationsRequest.startDate,
|
startDate = observationsRequest.startDate,
|
||||||
endDate = observationsRequest.endDate)
|
endDate = observationsRequest.endDate)
|
||||||
else -> observationRepository.findByTutorsAndWhomAndDateBetween(tutor = it,
|
else -> observationRepository.findByTutorsAndWhomIgnoreCaseAndDateBetween(tutor = it,
|
||||||
whom = observationsRequest.whom,
|
whom = observationsRequest.whom,
|
||||||
startDate = observationsRequest.startDate,
|
startDate = observationsRequest.startDate,
|
||||||
endDate = observationsRequest.endDate)
|
endDate = observationsRequest.endDate)
|
||||||
@ -138,14 +138,14 @@ class Controller {
|
|||||||
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)
|
||||||
else
|
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) {
|
} else if (observationsRequest.site != null) {
|
||||||
return siteRepository.findById(observationsRequest.site).map {
|
return siteRepository.findById(observationsRequest.site).map {
|
||||||
when {
|
when {
|
||||||
(observationsRequest.whom == null || observationsRequest.whom.isEmpty()) -> observationRepository.findBySiteAndDateBetween(site = it,
|
(observationsRequest.whom == null || observationsRequest.whom.isEmpty()) -> observationRepository.findBySiteAndDateBetween(site = it,
|
||||||
startDate = observationsRequest.startDate,
|
startDate = observationsRequest.startDate,
|
||||||
endDate = observationsRequest.endDate)
|
endDate = observationsRequest.endDate)
|
||||||
else -> observationRepository.findBySiteAndWhomAndDateBetween(site = it,
|
else -> observationRepository.findBySiteAndWhomIgnoreCaseAndDateBetween(site = it,
|
||||||
whom = observationsRequest.whom,
|
whom = observationsRequest.whom,
|
||||||
startDate = observationsRequest.startDate,
|
startDate = observationsRequest.startDate,
|
||||||
endDate = observationsRequest.endDate)
|
endDate = observationsRequest.endDate)
|
||||||
|
@ -17,13 +17,13 @@ interface ObservationRepository : CrudRepository<Observation, Long> {
|
|||||||
|
|
||||||
fun findByTutorsAndDateBetween(tutor: Tutor, startDate: LocalDate, endDate: LocalDate): List<Observation>
|
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 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
|
@Repository
|
||||||
|
@ -135,7 +135,7 @@ class ControllerTest {
|
|||||||
teamworkWorkload = 1.0, knowledge = 1.0, entries = listOf(), tutors = setOf(), persons = setOf())
|
teamworkWorkload = 1.0, knowledge = 1.0, entries = listOf(), tutors = setOf(), persons = setOf())
|
||||||
doReturn(Optional.of(site)).`when`(siteRepository).findById(1)
|
doReturn(Optional.of(site)).`when`(siteRepository).findById(1)
|
||||||
doReturn(listOf(observation))
|
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)
|
val result = controller.getObservations(request)
|
||||||
assertEquals(1, result.size)
|
assertEquals(1, result.size)
|
||||||
assertEquals(observation, result[0])
|
assertEquals(observation, result[0])
|
||||||
@ -169,7 +169,7 @@ class ControllerTest {
|
|||||||
teamworkWorkload = 1.0, knowledge = 1.0, entries = listOf(), tutors = setOf(tutor), persons = setOf())
|
teamworkWorkload = 1.0, knowledge = 1.0, entries = listOf(), tutors = setOf(tutor), persons = setOf())
|
||||||
doReturn(Optional.of(tutor)).`when`(tutorRepository).findById(1)
|
doReturn(Optional.of(tutor)).`when`(tutorRepository).findById(1)
|
||||||
doReturn(listOf(observation))
|
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)
|
val result = controller.getObservations(request)
|
||||||
assertEquals(1, result.size)
|
assertEquals(1, result.size)
|
||||||
assertEquals(observation, result[0])
|
assertEquals(observation, result[0])
|
||||||
|
@ -32,8 +32,8 @@ class RepositoryTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testFindBySiteAndWhomAndDateBetween_EmptyRepository() {
|
fun testFindBySiteAndWhomIgnoreCaseAndDateBetween_EmptyRepository() {
|
||||||
val result = observationRepository.findBySiteAndWhomAndDateBetween(Site(
|
val result = observationRepository.findBySiteAndWhomIgnoreCaseAndDateBetween(Site(
|
||||||
id = 1,
|
id = 1,
|
||||||
name = "x"
|
name = "x"
|
||||||
), "none", LocalDate.now(), LocalDate.now())
|
), "none", LocalDate.now(), LocalDate.now())
|
||||||
@ -51,8 +51,8 @@ class RepositoryTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testFindByTutorsAndWhomAndDateBetween_EmptyRepository() {
|
fun testFindByTutorsAndWhomIgnoreCaseAndDateBetween_EmptyRepository() {
|
||||||
val result = observationRepository.findByTutorsAndWhomAndDateBetween(Tutor(
|
val result = observationRepository.findByTutorsAndWhomIgnoreCaseAndDateBetween(Tutor(
|
||||||
id = 1,
|
id = 1,
|
||||||
name = "x",
|
name = "x",
|
||||||
site = Site(1, "x")
|
site = Site(1, "x")
|
||||||
@ -153,7 +153,7 @@ class RepositoryTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testFindBySiteAndWhomAndDateBetween() {
|
fun testFindBySiteAndWhomIgnoreCaseAndDateBetween() {
|
||||||
val correctSite = entityManager.persist(Site(name = "Correct"))
|
val correctSite = entityManager.persist(Site(name = "Correct"))
|
||||||
val incorrectSite = entityManager.persist(Site(name = "Incorrect"))
|
val incorrectSite = entityManager.persist(Site(name = "Incorrect"))
|
||||||
val person = entityManager.persist(Person(name = "Foo Bar"))
|
val person = entityManager.persist(Person(name = "Foo Bar"))
|
||||||
@ -254,7 +254,7 @@ class RepositoryTest {
|
|||||||
entityManager.persist(wrongSite)
|
entityManager.persist(wrongSite)
|
||||||
entityManager.persist(justRight)
|
entityManager.persist(justRight)
|
||||||
entityManager.persist(wrongWhom)
|
entityManager.persist(wrongWhom)
|
||||||
val result = observationRepository.findBySiteAndWhomAndDateBetween(
|
val result = observationRepository.findBySiteAndWhomIgnoreCaseAndDateBetween(
|
||||||
site = correctSite,
|
site = correctSite,
|
||||||
startDate = LocalDate.now().minusDays(1),
|
startDate = LocalDate.now().minusDays(1),
|
||||||
endDate = LocalDate.now().plusDays(1),
|
endDate = LocalDate.now().plusDays(1),
|
||||||
@ -381,7 +381,7 @@ class RepositoryTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testFindByTutorsAndWhomAndDateBetween() {
|
fun testFindByTutorsAndWhomIgnoreCaseAndDateBetween() {
|
||||||
val site = entityManager.persist(Site(name = "Correct"))
|
val site = entityManager.persist(Site(name = "Correct"))
|
||||||
val person = entityManager.persist(Person(name = "Foo Bar"))
|
val person = entityManager.persist(Person(name = "Foo Bar"))
|
||||||
val correctTutor = entityManager.persist(Tutor(name = "X", site = site))
|
val correctTutor = entityManager.persist(Tutor(name = "X", site = site))
|
||||||
@ -504,7 +504,7 @@ class RepositoryTest {
|
|||||||
entityManager.persist(correctTutor)
|
entityManager.persist(correctTutor)
|
||||||
incorrectTutor.observations.addAll(listOf(wrongTutor, justRightMultipleTutors))
|
incorrectTutor.observations.addAll(listOf(wrongTutor, justRightMultipleTutors))
|
||||||
entityManager.persist(incorrectTutor)
|
entityManager.persist(incorrectTutor)
|
||||||
val result = observationRepository.findByTutorsAndWhomAndDateBetween(
|
val result = observationRepository.findByTutorsAndWhomIgnoreCaseAndDateBetween(
|
||||||
tutor = correctTutor,
|
tutor = correctTutor,
|
||||||
startDate = LocalDate.now().minusDays(1),
|
startDate = LocalDate.now().minusDays(1),
|
||||||
endDate = LocalDate.now().plusDays(1),
|
endDate = LocalDate.now().plusDays(1),
|
||||||
|
Loading…
Reference in New Issue
Block a user