Queries are now ordered by date explicitly.

This commit is contained in:
neviyn 2018-11-22 16:40:32 +00:00
parent 821102f69b
commit e3a5dd7a46
4 changed files with 26 additions and 26 deletions

View File

@ -123,10 +123,10 @@ class Controller {
if (observationsRequest.tutor != null) {
return tutorRepository.findById(observationsRequest.tutor).map {
when {
(observationsRequest.whom == null || observationsRequest.whom.isEmpty()) -> observationRepository.findByTutorsAndDateBetween(tutor = it,
(observationsRequest.whom == null || observationsRequest.whom.isEmpty()) -> observationRepository.findByTutorsAndDateBetweenOrderByDateAsc(tutor = it,
startDate = observationsRequest.startDate,
endDate = observationsRequest.endDate)
else -> observationRepository.findByTutorsAndWhomIgnoreCaseAndDateBetween(tutor = it,
else -> observationRepository.findByTutorsAndWhomIgnoreCaseAndDateBetweenOrderByDateAsc(tutor = it,
whom = observationsRequest.whom,
startDate = observationsRequest.startDate,
endDate = observationsRequest.endDate)
@ -136,16 +136,16 @@ class Controller {
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)
observationRepository.findBySiteAndPersonsAndDateBetweenOrderByDateAsc(site, person, observationsRequest.startDate, observationsRequest.endDate)
else
observationRepository.findBySiteAndWhomIgnoreCaseAndPersonsAndDateBetween(site, observationsRequest.whom, person, observationsRequest.startDate, observationsRequest.endDate)
observationRepository.findBySiteAndWhomIgnoreCaseAndPersonsAndDateBetweenOrderByDateAsc(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,
(observationsRequest.whom == null || observationsRequest.whom.isEmpty()) -> observationRepository.findBySiteAndDateBetweenOrderByDateAsc(site = it,
startDate = observationsRequest.startDate,
endDate = observationsRequest.endDate)
else -> observationRepository.findBySiteAndWhomIgnoreCaseAndDateBetween(site = it,
else -> observationRepository.findBySiteAndWhomIgnoreCaseAndDateBetweenOrderByDateAsc(site = it,
whom = observationsRequest.whom,
startDate = observationsRequest.startDate,
endDate = observationsRequest.endDate)

View File

@ -13,17 +13,17 @@ interface TutorRepository : CrudRepository<Tutor, Long>
@Repository
interface ObservationRepository : CrudRepository<Observation, Long> {
fun findBySiteAndDateBetween(site: Site, startDate: LocalDate, endDate: LocalDate): List<Observation>
fun findBySiteAndDateBetweenOrderByDateAsc(site: Site, startDate: LocalDate, endDate: LocalDate): List<Observation>
fun findByTutorsAndDateBetween(tutor: Tutor, startDate: LocalDate, endDate: LocalDate): List<Observation>
fun findByTutorsAndDateBetweenOrderByDateAsc(tutor: Tutor, startDate: LocalDate, endDate: LocalDate): List<Observation>
fun findBySiteAndWhomIgnoreCaseAndDateBetween(site: Site, whom: String, startDate: LocalDate, endDate: LocalDate): List<Observation>
fun findBySiteAndWhomIgnoreCaseAndDateBetweenOrderByDateAsc(site: Site, whom: String, startDate: LocalDate, endDate: LocalDate): List<Observation>
fun findByTutorsAndWhomIgnoreCaseAndDateBetween(tutor: Tutor, whom: String, startDate: LocalDate, endDate: LocalDate): List<Observation>
fun findByTutorsAndWhomIgnoreCaseAndDateBetweenOrderByDateAsc(tutor: Tutor, whom: String, startDate: LocalDate, endDate: LocalDate): List<Observation>
fun findBySiteAndPersonsAndDateBetween(site: Site, person: Person, startDate: LocalDate, endDate: LocalDate): List<Observation>
fun findBySiteAndPersonsAndDateBetweenOrderByDateAsc(site: Site, person: Person, startDate: LocalDate, endDate: LocalDate): List<Observation>
fun findBySiteAndWhomIgnoreCaseAndPersonsAndDateBetween(site: Site, whom: String, person: Person, startDate: LocalDate, endDate: LocalDate): List<Observation>
fun findBySiteAndWhomIgnoreCaseAndPersonsAndDateBetweenOrderByDateAsc(site: Site, whom: String, person: Person, startDate: LocalDate, endDate: LocalDate): List<Observation>
}
@Repository

View File

@ -119,7 +119,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).findBySiteAndDateBetween(site, LocalDate.now(), LocalDate.now())
.`when`(observationRepository).findBySiteAndDateBetweenOrderByDateAsc(site, LocalDate.now(), LocalDate.now())
val result = controller.getObservations(request)
assertEquals(1, result.size)
assertEquals(observation, result[0])
@ -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).findBySiteAndWhomIgnoreCaseAndDateBetween(site, "Group A", LocalDate.now(), LocalDate.now())
.`when`(observationRepository).findBySiteAndWhomIgnoreCaseAndDateBetweenOrderByDateAsc(site, "Group A", LocalDate.now(), LocalDate.now())
val result = controller.getObservations(request)
assertEquals(1, result.size)
assertEquals(observation, result[0])
@ -152,7 +152,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).findByTutorsAndDateBetween(tutor, LocalDate.now(), LocalDate.now())
.`when`(observationRepository).findByTutorsAndDateBetweenOrderByDateAsc(tutor, 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).findByTutorsAndWhomIgnoreCaseAndDateBetween(tutor, "Group A", LocalDate.now(), LocalDate.now())
.`when`(observationRepository).findByTutorsAndWhomIgnoreCaseAndDateBetweenOrderByDateAsc(tutor, "Group A", LocalDate.now(), LocalDate.now())
val result = controller.getObservations(request)
assertEquals(1, result.size)
assertEquals(observation, result[0])
@ -187,7 +187,7 @@ class ControllerTest {
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).findFirstByNameLike("FOO BAR")
doReturn(listOf(observation)).`when`(observationRepository).findBySiteAndPersonsAndDateBetween(site, person, LocalDate.now(), LocalDate.now())
doReturn(listOf(observation)).`when`(observationRepository).findBySiteAndPersonsAndDateBetweenOrderByDateAsc(site, person, LocalDate.now(), LocalDate.now())
val result = controller.getObservations(request)
assertEquals(1, result.size)
assertEquals(observation, result[0])

View File

@ -24,7 +24,7 @@ class RepositoryTest {
@Test
fun testFindBySiteAndDateBetween_EmptyRepository() {
val result = observationRepository.findBySiteAndDateBetween(Site(
val result = observationRepository.findBySiteAndDateBetweenOrderByDateAsc(Site(
id = 1,
name = "x"
), LocalDate.now(), LocalDate.now())
@ -33,7 +33,7 @@ class RepositoryTest {
@Test
fun testFindBySiteAndWhomIgnoreCaseAndDateBetween_EmptyRepository() {
val result = observationRepository.findBySiteAndWhomIgnoreCaseAndDateBetween(Site(
val result = observationRepository.findBySiteAndWhomIgnoreCaseAndDateBetweenOrderByDateAsc(Site(
id = 1,
name = "x"
), "none", LocalDate.now(), LocalDate.now())
@ -42,7 +42,7 @@ class RepositoryTest {
@Test
fun testFindByTutorsAndDateBetween_EmptyRepository() {
val result = observationRepository.findByTutorsAndDateBetween(Tutor(
val result = observationRepository.findByTutorsAndDateBetweenOrderByDateAsc(Tutor(
id = 1,
name = "x",
site = Site(1, "x")
@ -52,7 +52,7 @@ class RepositoryTest {
@Test
fun testFindByTutorsAndWhomIgnoreCaseAndDateBetween_EmptyRepository() {
val result = observationRepository.findByTutorsAndWhomIgnoreCaseAndDateBetween(Tutor(
val result = observationRepository.findByTutorsAndWhomIgnoreCaseAndDateBetweenOrderByDateAsc(Tutor(
id = 1,
name = "x",
site = Site(1, "x")
@ -143,7 +143,7 @@ class RepositoryTest {
entityManager.persist(tooLate)
entityManager.persist(wrongSite)
entityManager.persist(justRight)
val result = observationRepository.findBySiteAndDateBetween(
val result = observationRepository.findBySiteAndDateBetweenOrderByDateAsc(
site = correctSite,
startDate = LocalDate.now().minusDays(1),
endDate = LocalDate.now().plusDays(1)
@ -254,7 +254,7 @@ class RepositoryTest {
entityManager.persist(wrongSite)
entityManager.persist(justRight)
entityManager.persist(wrongWhom)
val result = observationRepository.findBySiteAndWhomIgnoreCaseAndDateBetween(
val result = observationRepository.findBySiteAndWhomIgnoreCaseAndDateBetweenOrderByDateAsc(
site = correctSite,
startDate = LocalDate.now().minusDays(1),
endDate = LocalDate.now().plusDays(1),
@ -369,7 +369,7 @@ class RepositoryTest {
entityManager.persist(correctTutor)
incorrectTutor.observations.addAll(listOf(wrongTutor, justRightMultipleTutors))
entityManager.persist(incorrectTutor)
val result = observationRepository.findByTutorsAndDateBetween(
val result = observationRepository.findByTutorsAndDateBetweenOrderByDateAsc(
tutor = correctTutor,
startDate = LocalDate.now().minusDays(1),
endDate = LocalDate.now().plusDays(1)
@ -504,7 +504,7 @@ class RepositoryTest {
entityManager.persist(correctTutor)
incorrectTutor.observations.addAll(listOf(wrongTutor, justRightMultipleTutors))
entityManager.persist(incorrectTutor)
val result = observationRepository.findByTutorsAndWhomIgnoreCaseAndDateBetween(
val result = observationRepository.findByTutorsAndWhomIgnoreCaseAndDateBetweenOrderByDateAsc(
tutor = correctTutor,
startDate = LocalDate.now().minusDays(1),
endDate = LocalDate.now().plusDays(1),
@ -599,7 +599,7 @@ class RepositoryTest {
entityManager.persist(tooLate)
entityManager.persist(wrongPerson)
entityManager.persist(justRight)
val result = observationRepository.findBySiteAndPersonsAndDateBetween(
val result = observationRepository.findBySiteAndPersonsAndDateBetweenOrderByDateAsc(
site = site,
person = person,
startDate = LocalDate.now().minusDays(1),