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