Skip to content

Commit

Permalink
Merge pull request #175 from swm-nodriversomabus/BUS-198-Matching-par…
Browse files Browse the repository at this point in the history
…ticipant-number

feat(BE): 매칭 참가자 수 조회 BUS-198-Matching-participant-number #172
  • Loading branch information
Lemonade255 authored Nov 7, 2023
2 parents 01b10b7 + c630965 commit 3eb6b92
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -56,31 +57,33 @@ public MatchingApplication createMatchingApplicationData(UUID userId, SaveMatchi
@Override
public List<FindMatchingDto> getByUserIdIsAndStateEquals(UUID userId, ApplicationStateEnum state) {
List<MatchingApplicationEntity> matchingPairList = matchingApplicationPort.getByUserIdIsAndStateEquals(userId, state);
List<FindMatchingDto> matchingData = new ArrayList<>();
List<FindMatchingDto> matchingList = new ArrayList<>();
for (MatchingApplicationEntity matchingPair: matchingPairList) {
Optional<MatchingEntity> 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<FindUserInfoDto> getByMatchingIdIsAndStateEquals(Long matchingId, ApplicationStateEnum state) {
List<MatchingApplicationEntity> matchingPairList = matchingApplicationPort.getByMatchingIdIsAndStateEquals(matchingId, state);
List<FindUserInfoDto> userData = new ArrayList<>();
List<FindUserInfoDto> userList = new ArrayList<>();
for (MatchingApplicationEntity matchingPair: matchingPairList) {
Optional<UserEntity> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,8 @@ public FindMatchingDto createMatching(UUID writerId, SaveMatchingDto matchingDto
matching.setWriterId(writerId);
return matchingMapper.toDto(saveMatchingPort.createMatching(matching));
}

@Override
public List<FindMatchingDto> getAll() {
List<MatchingEntity> matchingEntities = findMatchingPort.getAllBy();

public List<FindMatchingDto> setCurrentMember(List<MatchingEntity> matchingEntities) {
List<FindMatchingDto> matchingList = new ArrayList<>();
for (MatchingEntity matchingData: matchingEntities) {
Matching matching = matchingMapper.toDomain(matchingData);
Expand All @@ -54,6 +52,11 @@ public List<FindMatchingDto> getAll() {
return matchingList;
}

@Override
public List<FindMatchingDto> getAll() {
return this.setCurrentMember(findMatchingPort.getAllBy());
}

@Override
public FindMatchingDto getMatchingById(Long matchingId) {
Optional<MatchingEntity> matchingEntity = findMatchingPort.getByMatchingId(matchingId);
Expand All @@ -67,26 +70,12 @@ public FindMatchingDto getMatchingById(Long matchingId) {

@Override
public List<FindMatchingDto> getMatchingByWriterId(UUID userId) {
List<MatchingEntity> matchingEntities = findMatchingPort.getByWriterId(userId);
List<FindMatchingDto> 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<FindMatchingDto> getMatchingByIsActive(Boolean isActive) {
List<MatchingEntity> matchingEntities = findMatchingPort.getByIsActive(isActive);
List<FindMatchingDto> 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
Expand Down

0 comments on commit 3eb6b92

Please sign in to comment.