diff --git a/src/main/java/com/example/api/matching/service/MatchingApplicationService.java b/src/main/java/com/example/api/matching/service/MatchingApplicationService.java index ef9e813..1f747de 100644 --- a/src/main/java/com/example/api/matching/service/MatchingApplicationService.java +++ b/src/main/java/com/example/api/matching/service/MatchingApplicationService.java @@ -12,6 +12,7 @@ import com.example.api.matching.application.port.in.MatchingApplicationUsecase; import com.example.api.matching.application.port.out.FindMatchingPort; import com.example.api.matching.application.port.out.MatchingApplicationPort; +import com.example.api.matching.domain.Matching; import com.example.api.matching.domain.MatchingApplication; import com.example.api.matching.dto.FindMatchingDto; import com.example.api.matching.dto.SaveMatchingApplicationDto; @@ -56,31 +57,33 @@ public MatchingApplication createMatchingApplicationData(UUID userId, SaveMatchi @Override public List getByUserIdIsAndStateEquals(UUID userId, ApplicationStateEnum state) { List matchingPairList = matchingApplicationPort.getByUserIdIsAndStateEquals(userId, state); - List matchingData = new ArrayList<>(); + List matchingList = new ArrayList<>(); for (MatchingApplicationEntity matchingPair: matchingPairList) { Optional matchingEntity = findMatchingPort.getByMatchingId(matchingPair.getMatchingId()); if (matchingEntity.isEmpty()) { log.warn("MatchingApplicationService::getByUserIdIsAndStateEquals: Matching with ID {} doesn't exist", matchingPair.getMatchingId()); } else { - matchingData.add(matchingMapper.toDto(matchingEntity.get())); + Matching matching = matchingMapper.toDomain(matchingEntity.get()); + matching.setCurrentMember(matchingApplicationPort.getByMatchingIdIsAndStateEquals(matching.getMatchingId(), ApplicationStateEnum.Approved).size() + 1); + matchingList.add(matchingMapper.toDto(matching)); } } - return matchingData; + return matchingList; } @Override public List getByMatchingIdIsAndStateEquals(Long matchingId, ApplicationStateEnum state) { List matchingPairList = matchingApplicationPort.getByMatchingIdIsAndStateEquals(matchingId, state); - List userData = new ArrayList<>(); + List userList = new ArrayList<>(); for (MatchingApplicationEntity matchingPair: matchingPairList) { Optional userEntity = findUserPort.getByUserId(matchingPair.getUserId()); if (userEntity.isEmpty()) { log.warn("MatchingApplicationService::getByMatchingIdIsAndStateEquals: User with ID {} doesn't exist", matchingPair.getUserId()); } else { - userData.add(userMapper.toInfoDto(userEntity.get())); + userList.add(userMapper.toInfoDto(userEntity.get())); } } - return userData; + return userList; } @Override diff --git a/src/main/java/com/example/api/matching/service/MatchingService.java b/src/main/java/com/example/api/matching/service/MatchingService.java index 90a0823..b78eba0 100644 --- a/src/main/java/com/example/api/matching/service/MatchingService.java +++ b/src/main/java/com/example/api/matching/service/MatchingService.java @@ -41,10 +41,8 @@ public FindMatchingDto createMatching(UUID writerId, SaveMatchingDto matchingDto matching.setWriterId(writerId); return matchingMapper.toDto(saveMatchingPort.createMatching(matching)); } - - @Override - public List getAll() { - List matchingEntities = findMatchingPort.getAllBy(); + + public List setCurrentMember(List matchingEntities) { List matchingList = new ArrayList<>(); for (MatchingEntity matchingData: matchingEntities) { Matching matching = matchingMapper.toDomain(matchingData); @@ -54,6 +52,11 @@ public List getAll() { return matchingList; } + @Override + public List getAll() { + return this.setCurrentMember(findMatchingPort.getAllBy()); + } + @Override public FindMatchingDto getMatchingById(Long matchingId) { Optional matchingEntity = findMatchingPort.getByMatchingId(matchingId); @@ -67,26 +70,12 @@ public FindMatchingDto getMatchingById(Long matchingId) { @Override public List getMatchingByWriterId(UUID userId) { - List matchingEntities = findMatchingPort.getByWriterId(userId); - List matchingList = new ArrayList<>(); - for (MatchingEntity matchingData: matchingEntities) { - Matching matching = matchingMapper.toDomain(matchingData); - matching.setCurrentMember(matchingApplicationPort.getByMatchingIdIsAndStateEquals(matchingData.getMatchingId(), ApplicationStateEnum.Approved).size() + 1); - matchingList.add(matchingMapper.toDto(matching)); - } - return matchingList; + return this.setCurrentMember(findMatchingPort.getByWriterId(userId)); } @Override public List getMatchingByIsActive(Boolean isActive) { - List matchingEntities = findMatchingPort.getByIsActive(isActive); - List matchingList = new ArrayList<>(); - for (MatchingEntity matchingData: matchingEntities) { - Matching matching = matchingMapper.toDomain(matchingData); - matching.setCurrentMember(matchingApplicationPort.getByMatchingIdIsAndStateEquals(matchingData.getMatchingId(), ApplicationStateEnum.Approved).size() + 1); - matchingList.add(matchingMapper.toDto(matching)); - } - return matchingList; + return this.setCurrentMember(findMatchingPort.getByIsActive(isActive)); } @Override