From b8a068b95bd7c2ec5342d748a237ce9a5871c9eb Mon Sep 17 00:00:00 2001 From: tkuzynow Date: Wed, 28 Feb 2024 15:08:14 +0100 Subject: [PATCH] fix: make postcode optional for agency search --- .../api/repository/agency/AgencyRepository.java | 8 ++++---- .../api/repository/agency/AgencyRepositoryIT.java | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/java/de/caritas/cob/agencyservice/api/repository/agency/AgencyRepository.java b/src/main/java/de/caritas/cob/agencyservice/api/repository/agency/AgencyRepository.java index 0d4fd616..dce30e15 100644 --- a/src/main/java/de/caritas/cob/agencyservice/api/repository/agency/AgencyRepository.java +++ b/src/main/java/de/caritas/cob/agencyservice/api/repository/agency/AgencyRepository.java @@ -16,8 +16,8 @@ public interface AgencyRepository extends JpaRepository { String SELECT_WITH_TOPICS = "SELECT a.*, :tenantId FROM agency a " + "LEFT JOIN agency_postcode_range r ON a.id = r.agency_id " + "INNER JOIN agency_topic at ON a.id = at.agency_id " - + "WHERE :postcode is NULL OR ((CAST(:postcode AS INT) BETWEEN CAST(SUBSTR(r.postcode_from, 1, :length) AS int) " - + "AND CAST(SUBSTR(r.postcode_to, 1, :length) AS int))) " + "AND a.is_offline = false " + + "WHERE (:postcode is NULL OR ((CAST(:postcode AS INT) BETWEEN CAST(SUBSTR(r.postcode_from, 1, :length) AS int) " + + "AND CAST(SUBSTR(r.postcode_to, 1, :length) AS int)))) " + "AND a.is_offline = false " + "AND (:type is NULL OR a.consulting_type = :type) " + "AND at.topic_id = :topicId " + AND_WITH_BRACKET @@ -33,8 +33,8 @@ public interface AgencyRepository extends JpaRepository { String SELECT_WITHOUT_TOPICS = "SELECT a.*, :tenantId FROM agency a " + "LEFT JOIN agency_postcode_range r ON a.id = r.agency_id " + "WHERE " - + ":postcode is NULL OR ((CAST(:postcode AS INT) BETWEEN CAST(SUBSTR(r.postcode_from, 1, :length) AS int) " - + "AND CAST(SUBSTR(r.postcode_to, 1, :length) AS int))) " + "AND a.is_offline = false " + + "(:postcode is NULL OR ((CAST(:postcode AS INT) BETWEEN CAST(SUBSTR(r.postcode_from, 1, :length) AS int) " + + "AND CAST(SUBSTR(r.postcode_to, 1, :length) AS int)))) " + "AND a.is_offline = false " + "AND (:type is NULL OR a.consulting_type = :type) " + AND_WITH_BRACKET + " (:age IS NULL) OR (a.age_from <= :age)" diff --git a/src/test/java/de/caritas/cob/agencyservice/api/repository/agency/AgencyRepositoryIT.java b/src/test/java/de/caritas/cob/agencyservice/api/repository/agency/AgencyRepositoryIT.java index 5e6d177d..f0db961d 100644 --- a/src/test/java/de/caritas/cob/agencyservice/api/repository/agency/AgencyRepositoryIT.java +++ b/src/test/java/de/caritas/cob/agencyservice/api/repository/agency/AgencyRepositoryIT.java @@ -60,7 +60,7 @@ void searchWithoutTopic_Should_findAgencyByOnlyConsultingTypeSkippingPostCodeFil // given, when var agencyList = agencyRepository.searchWithoutTopic(null, 5, 0, null, null, null, 1L); // then - assertThat(agencyList).hasSize(1138); + assertThat(agencyList).hasSize(104); } @@ -79,7 +79,7 @@ void searchWithTopic_Should_findAgencyConsultingTypeAndTopicIdSkippingPostCode() // given, when var agencyList = agencyRepository.searchWithTopic(null, 5, 0, 1, null, null, null, 1L); // then - assertThat(agencyList).hasSize(4); + assertThat(agencyList).hasSize(2); } @Test