diff --git a/src/main/java/de/caritas/cob/userservice/api/admin/service/agency/ConsultantAgencyAdminService.java b/src/main/java/de/caritas/cob/userservice/api/admin/service/agency/ConsultantAgencyAdminService.java index e21b5d232..eed7588b2 100644 --- a/src/main/java/de/caritas/cob/userservice/api/admin/service/agency/ConsultantAgencyAdminService.java +++ b/src/main/java/de/caritas/cob/userservice/api/admin/service/agency/ConsultantAgencyAdminService.java @@ -77,7 +77,8 @@ public ConsultantAgencyResponseDTO findConsultantAgencies(String consultantId) { public void appendAgenciesForConsultants(Set consultants) { var consultantIds = consultants.stream().map(ConsultantDTO::getId).collect(Collectors.toSet()); - var consultantAgencies = consultantAgencyRepository.findByConsultantIdIn(consultantIds); + var consultantAgencies = + consultantAgencyRepository.findByConsultantIdInAndDeleteDateIsNull(consultantIds); var agencyIds = consultantAgencies.stream().map(ConsultantAgency::getAgencyId).collect(Collectors.toSet()); diff --git a/src/main/java/de/caritas/cob/userservice/api/port/out/ConsultantAgencyRepository.java b/src/main/java/de/caritas/cob/userservice/api/port/out/ConsultantAgencyRepository.java index 9347f3533..b9a90df76 100644 --- a/src/main/java/de/caritas/cob/userservice/api/port/out/ConsultantAgencyRepository.java +++ b/src/main/java/de/caritas/cob/userservice/api/port/out/ConsultantAgencyRepository.java @@ -34,6 +34,8 @@ ConsultantAgency findByConsultantIdAndAgencyIdAndStatusAndDeleteDateIsNull( List findByConsultantIdIn(Set consultantIds); + List findByConsultantIdInAndDeleteDateIsNull(Set consultantIds); + @SuppressWarnings("all") List findByConsultantIdIn(List consultantIds); } diff --git a/src/test/java/de/caritas/cob/userservice/api/admin/service/agency/ConsultantAgencyAdminUserServiceTest.java b/src/test/java/de/caritas/cob/userservice/api/admin/service/agency/ConsultantAgencyAdminUserServiceTest.java index 1af1811c9..a68b45797 100644 --- a/src/test/java/de/caritas/cob/userservice/api/admin/service/agency/ConsultantAgencyAdminUserServiceTest.java +++ b/src/test/java/de/caritas/cob/userservice/api/admin/service/agency/ConsultantAgencyAdminUserServiceTest.java @@ -14,6 +14,7 @@ import static org.mockito.Mockito.when; import de.caritas.cob.userservice.api.adapters.web.dto.AgencyDTO; +import de.caritas.cob.userservice.api.adapters.web.dto.ConsultantDTO; import de.caritas.cob.userservice.api.exception.httpresponses.CustomValidationHttpStatusException; import de.caritas.cob.userservice.api.exception.httpresponses.InternalServerErrorException; import de.caritas.cob.userservice.api.model.Consultant; @@ -25,6 +26,7 @@ import de.caritas.cob.userservice.api.service.agency.AgencyService; import java.util.Collections; import java.util.List; +import java.util.Set; import java.util.stream.Collectors; import org.jeasy.random.EasyRandom; import org.junit.jupiter.api.Test; @@ -137,6 +139,16 @@ public void removeConsultantsFromTeamSessionsByAgencyId_Should_changeTeamSession }); } + @Test + void appendAgenciesForConsultants_Should_callConsultantAgencyRepositoryForNotDeletedEntries() { + ConsultantDTO consultantDTO = new EasyRandom().nextObject(ConsultantDTO.class); + + this.consultantAgencyAdminService.appendAgenciesForConsultants(Set.of(consultantDTO)); + + verify(consultantAgencyRepository).findByConsultantIdInAndDeleteDateIsNull(any()); + verify(agencyAdminService).retrieveAllAgencies(); + } + @Test public void markConsultantAgencyForDeletion_Should_throwCustomValidationHttpStatusException_When_relationDoesNotExist() {