From 24b9f471ccbc9dd1c807f8909f22c0203e15be6a Mon Sep 17 00:00:00 2001 From: LeandroSilva Date: Fri, 8 Nov 2024 16:32:03 +0100 Subject: [PATCH] feat: CARITAS-286 * fix the db call for topics --- .../api/repository/agency/AgencyRepository.java | 2 +- .../api/repository/agency/AgencyTenantAwareRepository.java | 2 +- .../repository/agency/AgencyTenantUnawareRepository.java | 6 ------ .../cob/agencyservice/api/service/AgencyService.java | 2 +- .../cob/agencyservice/api/service/AgencyServiceTest.java | 4 ++-- 5 files changed, 5 insertions(+), 11 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 99b7e341..31d11de5 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 @@ -89,7 +89,7 @@ List searchWithTopic(@Param(value = "postcode") String postCode, value = SELECT_ALL_AGENCIES_TOPICS + ORDER_BY_TOPIC, nativeQuery = true) - List findAllAgenciesTopics(); + List findAllAgenciesTopics(Long tenantId); Optional findByIdAndDeleteDateNull(Long agencyId); diff --git a/src/main/java/de/caritas/cob/agencyservice/api/repository/agency/AgencyTenantAwareRepository.java b/src/main/java/de/caritas/cob/agencyservice/api/repository/agency/AgencyTenantAwareRepository.java index 67af34ac..20c0c4e2 100644 --- a/src/main/java/de/caritas/cob/agencyservice/api/repository/agency/AgencyTenantAwareRepository.java +++ b/src/main/java/de/caritas/cob/agencyservice/api/repository/agency/AgencyTenantAwareRepository.java @@ -55,7 +55,7 @@ List searchWithTopic(@Param(value = "postcode") String postCode, + AND_A_TENANT_ID_FILTER + ORDER_BY_TOPIC, nativeQuery = true) - List findAllAgenciesTopics(); + List findAllAgenciesTopics(Long tenantId); @Query("select a from Agency as a where a.id = :agencyId ") Optional findById(Long agencyId); diff --git a/src/main/java/de/caritas/cob/agencyservice/api/repository/agency/AgencyTenantUnawareRepository.java b/src/main/java/de/caritas/cob/agencyservice/api/repository/agency/AgencyTenantUnawareRepository.java index 1f6c5454..bde9c048 100644 --- a/src/main/java/de/caritas/cob/agencyservice/api/repository/agency/AgencyTenantUnawareRepository.java +++ b/src/main/java/de/caritas/cob/agencyservice/api/repository/agency/AgencyTenantUnawareRepository.java @@ -38,12 +38,6 @@ List searchWithTopic(@Param(value = "postcode") String postCode, @Param(value = "gender") String gender, Long tenantId); - @Query( - value = SELECT_ALL_AGENCIES_TOPICS - + ORDER_BY_TOPIC, - nativeQuery = true) - List findAllAgenciesTopics(); - Optional findByIdAndDeleteDateNull(Long agencyId); List findByIdIn(List agencyIds); diff --git a/src/main/java/de/caritas/cob/agencyservice/api/service/AgencyService.java b/src/main/java/de/caritas/cob/agencyservice/api/service/AgencyService.java index 05dd7ad5..193083ea 100644 --- a/src/main/java/de/caritas/cob/agencyservice/api/service/AgencyService.java +++ b/src/main/java/de/caritas/cob/agencyservice/api/service/AgencyService.java @@ -153,7 +153,7 @@ public List getAgencies(String postCode, Integer topicId) } public List getAgenciesTopics() { - return agencyRepository.findAllAgenciesTopics(); + return agencyRepository.findAllAgenciesTopics(TenantContext.getCurrentTenant()); } private Optional getConsultingTypeIdForSearch(int consultingTypeId) { diff --git a/src/test/java/de/caritas/cob/agencyservice/api/service/AgencyServiceTest.java b/src/test/java/de/caritas/cob/agencyservice/api/service/AgencyServiceTest.java index 21d670d4..11882d69 100644 --- a/src/test/java/de/caritas/cob/agencyservice/api/service/AgencyServiceTest.java +++ b/src/test/java/de/caritas/cob/agencyservice/api/service/AgencyServiceTest.java @@ -341,7 +341,7 @@ public void getAgencies_Should_searchByTopicId_When_TopicIdProvidedAndFeatureEna @Test public void getAgenciesTopics_Should_ReturnListOfTopicIds_When_topicsExist() { - when(agencyRepository.findAllAgenciesTopics()) + when(agencyRepository.findAllAgenciesTopics(TenantContext.getCurrentTenant())) .thenReturn(TOPIC_ID_LIST); Integer result = agencyService.getAgenciesTopics().get(0); @@ -352,7 +352,7 @@ public void getAgenciesTopics_Should_ReturnListOfTopicIds_When_topicsExist() { @Test public void getAgenciesTopics_Should_ReturnEmptyListOfTopicIds_When_topicsDontExist() { - when(agencyRepository.findAllAgenciesTopics()) + when(agencyRepository.findAllAgenciesTopics(TenantContext.getCurrentTenant())) .thenReturn(new ArrayList<>()); List result = agencyService.getAgenciesTopics();