Skip to content

Commit

Permalink
Merge pull request #173 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 6, 2023
2 parents 6b159e0 + 21a7ea7 commit d4bbe7a
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
import com.example.api.matching.dto.*;
import com.example.api.member.application.port.in.AddMemberChatRoomUsecase;
import com.example.api.user.application.port.in.FindUserUsecase;
import com.example.api.user.dto.FindUserDto;
import com.example.api.user.dto.FindUserInfoDto;
import com.example.api.user.dto.UserAuthorityCheckDto;
import com.example.api.user.type.UserRoleEnum;
import io.swagger.v3.oas.annotations.Operation;
Expand All @@ -24,7 +22,6 @@
import org.springframework.web.servlet.config.annotation.EnableWebMvc;

import java.util.List;
import java.util.Optional;

@RestController
@RequiredArgsConstructor
Expand All @@ -44,7 +41,7 @@ public class MatchingController {
/**
* 새 매칭 생성
* @param saveMatchingDto (데이터)
* @return FindMatchingDto
* @return matching data
*/
@Operation(summary = "Create matching", description = "새로운 매칭을 생성한다.")
@PostMapping("/matching")
Expand All @@ -69,13 +66,13 @@ public FindMatchingDto createMatching(@RequestBody SaveMatchingDto saveMatchingD
/**
* 새 매칭 신청 생성
* @param matchingApplicationDto (데이터)
* @return ChatRoom
* @return chatroom
*/
@Operation(summary = "Create matching application", description = "새로운 매칭 신청을 생성한다.")
@PostMapping("/matching/application")
public ChatRoom createMatchingApplication(@RequestBody SaveMatchingApplicationDto matchingApplicationDto) {
Optional<FindMatchingDto> matchingDto = findMatchingUsecase.getMatchingById(matchingApplicationDto.getMatchingId());
if (matchingDto.isEmpty()) {
FindMatchingDto matchingDto = findMatchingUsecase.getMatchingById(matchingApplicationDto.getMatchingId());
if (matchingDto == null) {
log.error("MatchingController::createMatchingApplication: No such matching");
throw new CustomException(ErrorCodeEnum.MATCHING_NOT_FOUND);
}
Expand All @@ -97,7 +94,7 @@ public ChatRoom createMatchingApplication(@RequestBody SaveMatchingApplicationDt

/**
* 전체 매칭 목록 조회
* @return List<MatchingDto>
* @return matching list
*/
@Operation(summary = "Get all matching", description = "모든 매칭 목록을 조회한다.")
@GetMapping ("/matching")
Expand All @@ -108,36 +105,41 @@ public List<FindMatchingDto> getAll() {
/**
* ID가 matchingId인 매칭 조회
* @param matchingId (데이터)
* @return Optional<MatchingDto>
* @return matching data
*/
@Operation(summary = "Get matching", description = "ID가 matchingId인 매칭을 조회한다.")
@GetMapping("/matching/{matchingId}")
public Optional<FindMatchingDto> getMatchingById(@PathVariable Long matchingId) {
public FindMatchingDto getMatchingById(@PathVariable Long matchingId) {
return findMatchingUsecase.getMatchingById(matchingId);
}

/**
* ID가 matchingId인 매칭의 대기자 목록 조회
* @param matchingId (ID)
* @return List<UserDto>
* @return pending user list
*/
@Operation(summary = "Get pending user list of matching", description = "매칭의 대기자 목록을 조회한다.")
@GetMapping("/matching/{matchingId}/pending")
public List<FindUserInfoDto> getPendingUserList(@PathVariable Long matchingId) {
public List<Object> getPendingUserList(@PathVariable Long matchingId) {
return matchingApplicationUsecase.getByMatchingIdIsAndStateEquals(matchingId, ApplicationStateEnum.Pending);
}

/**
* ID가 matchingId인 매칭의 참가자 목록 조회
* @param matchingId (ID)
* @return List<UserDto>
* @return participant list
*/
@Operation(summary = "Get approved user list of matching", description = "매칭의 참가자 목록을 조회한다.")
@GetMapping("/matching/{matchingId}/approved")
public List<FindUserInfoDto> getApprovedUserList(@PathVariable Long matchingId) {
public List<Object> getApprovedUserList(@PathVariable Long matchingId) {
return matchingApplicationUsecase.getByMatchingIdIsAndStateEquals(matchingId, ApplicationStateEnum.Approved);
}


/**
* Id가 matchingId인 매칭의 사용자 상태 조회
* @param matchingId (ID)
* @return user status
*/
@Operation(summary = "Get user status of matching", description = "매칭의 사용자 상태를 조회한다.")
@GetMapping("/matching/{matchingId}/status")
public String getUserStatus(@PathVariable Long matchingId) {
Expand All @@ -152,7 +154,7 @@ public String getUserStatus(@PathVariable Long matchingId) {
/**
* ID가 matchingId인 매칭의 좋아요 수 조회
* @param matchingId (ID)
* @return int
* @return like count
*/
@Operation(summary = "Get like count of a matching", description = "매칭글의 좋아요 수를 반환한다.")
@GetMapping("/matching/{matchingId}/like")
Expand All @@ -164,7 +166,7 @@ public int getLikeCount(@PathVariable Long matchingId) {
* ID가 matchingId인 매칭 정보 수정
* @param matchingId (ID)
* @param matchingDto (데이터)
* @return MatchingDto
* @return matching data
*/
@Operation(summary = "Update matching", description = "매칭 정보를 수정한다.")
@PutMapping("/matching/{matchingId}")
Expand Down Expand Up @@ -224,13 +226,13 @@ public void deleteMatching(@PathVariable Long matchingId) {
}

UserAuthorityCheckDto userDto = findUserUsecase.getAuthorityUser(securityUser.getUserId());
Optional<FindMatchingDto> matchingDto = findMatchingUsecase.getMatchingById(matchingId);
if (matchingDto.isEmpty()) {
FindMatchingDto matchingDto = findMatchingUsecase.getMatchingById(matchingId);
if (matchingDto == null) {
log.error("MatchingController::deleteMatching: No such matching");
throw new CustomException(ErrorCodeEnum.MATCHING_NOT_FOUND);
}

if (!(userDto.getRole().equals(UserRoleEnum.Admin)) && !(userDto.getUserId().equals(matchingDto.get().getWriterId()))) {
if (!(userDto.getRole().equals(UserRoleEnum.Admin)) && !(userDto.getUserId().equals(matchingDto.getWriterId()))) {
log.error("MatchingController::deleteMatching: Admin or owner authority is needed");
throw new CustomException(ErrorCodeEnum.INVALID_PERMISSION);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

public interface FindMatchingUsecase {
List<FindMatchingDto> getAll();
Optional<FindMatchingDto> getMatchingById(Long matchingId);
FindMatchingDto getMatchingById(Long matchingId);
List<FindMatchingDto> getMatchingByWriterId(UUID userId);
List<FindMatchingDto> getMatchingByIsActive(Boolean isActive);
List<FindMatchingDto> getRecommendedMatchingList(UUID userId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@
import com.example.api.matching.domain.MatchingApplication;
import com.example.api.matching.dto.SaveMatchingApplicationDto;
import com.example.api.matching.dto.FindMatchingDto;
import com.example.api.user.dto.FindUserInfoDto;

import java.util.List;
import java.util.UUID;

public interface MatchingApplicationUsecase {
MatchingApplication createMatchingApplicationData(UUID userId, SaveMatchingApplicationDto matchingApplicationDto);
List<FindMatchingDto> getByUserIdIsAndStateEquals(UUID userId, ApplicationStateEnum state);
List<FindUserInfoDto> getByMatchingIdIsAndStateEquals(Long matchingId, ApplicationStateEnum state);
List<Object> getByMatchingIdIsAndStateEquals(Long matchingId, ApplicationStateEnum state);
String getUserStatus(UUID userId, Long matchingId);
void processMatchingApplication(SaveMatchingApplicationDto matchingApplicationDto);
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class Matching {
private String content;
private LocalDateTime startDate;
private LocalDateTime endDate;
private Integer currentMember;
private Integer maxMember;
private Integer minusAge;
private Integer plusAge;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ public class FindMatchingDto {
@NotNull
private LocalDateTime endDate;

@NotNull
@Min(1)
private Integer currentMember;

@NotNull
@Min(1)
private Integer maxMember;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import com.example.api.user.adapter.out.persistence.UserEntity;
import com.example.api.user.adapter.out.persistence.UserMapperInterface;
import com.example.api.user.application.port.out.FindUserPort;
import com.example.api.user.dto.FindUserDto;
import com.example.api.user.dto.FindUserInfoDto;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
Expand Down Expand Up @@ -70,7 +69,7 @@ public List<FindMatchingDto> getByUserIdIsAndStateEquals(UUID userId, Applicatio
}

@Override
public List<FindUserInfoDto> getByMatchingIdIsAndStateEquals(Long matchingId, ApplicationStateEnum state) {
public List<Object> getByMatchingIdIsAndStateEquals(Long matchingId, ApplicationStateEnum state) {
List<MatchingApplicationEntity> matchingPairList = matchingApplicationPort.getByMatchingIdIsAndStateEquals(matchingId, state);
List<FindUserInfoDto> userData = new ArrayList<>();
for (MatchingApplicationEntity matchingPair: matchingPairList) {
Expand All @@ -81,7 +80,10 @@ public List<FindUserInfoDto> getByMatchingIdIsAndStateEquals(Long matchingId, Ap
userData.add(userMapper.toInfoDto(userEntity.get()));
}
}
return userData;
List<Object> data = new ArrayList<>();
data.add(userData);
data.add(userData.size());
return data;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
package com.example.api.matching.service;

import com.example.api.common.type.ApplicationStateEnum;
import com.example.api.common.type.Pair;
import com.example.api.matching.adapter.out.persistence.MatchingEntity;
import com.example.api.matching.adapter.out.persistence.MatchingMapperInterface;
import com.example.api.matching.application.port.in.DeleteMatchingUsecase;
import com.example.api.matching.application.port.in.FindMatchingUsecase;
import com.example.api.matching.application.port.in.LikeUsecase;
import com.example.api.matching.application.port.out.*;
import com.example.api.matching.domain.Matching;
import com.example.api.matching.application.port.in.SaveMatchingUsecase;
import com.example.api.matching.application.port.out.DeleteMatchingPort;
import com.example.api.matching.application.port.out.FindMatchingPort;
import com.example.api.matching.application.port.out.LikePort;
import com.example.api.matching.application.port.out.SaveMatchingPort;
import com.example.api.matching.dto.FindMatchingDto;
import com.example.api.matching.dto.LikeDto;
import com.example.api.matching.dto.SaveMatchingDto;
Expand All @@ -33,6 +32,7 @@ public class MatchingService implements SaveMatchingUsecase, FindMatchingUsecase
private final SaveMatchingPort saveMatchingPort;
private final FindMatchingPort findMatchingPort;
private final DeleteMatchingPort deleteMatchingPort;
private final MatchingApplicationPort matchingApplicationPort;
private final LikePort likePort;

@Override
Expand All @@ -51,9 +51,14 @@ public List<FindMatchingDto> getAll() {
}

@Override
public Optional<FindMatchingDto> getMatchingById(Long matchingId) {
return findMatchingPort.getByMatchingId(matchingId)
.map(matchingMapper::toDto);
public FindMatchingDto getMatchingById(Long matchingId) {
Optional<MatchingEntity> matchingEntity = findMatchingPort.getByMatchingId(matchingId);
if (matchingEntity.isEmpty()) {
return null;
}
Matching matching = matchingMapper.toDomain(matchingEntity.get());
matching.setCurrentMember(matchingApplicationPort.getByMatchingIdIsAndStateEquals(matchingId, ApplicationStateEnum.Approved).size() + 1);
return matchingMapper.toDto(matching);
}

@Override
Expand Down Expand Up @@ -83,8 +88,10 @@ public List<FindMatchingDto> getRecommendedMatchingList(UUID userId) {
List<FindMatchingDto> sortedMatchingList = new ArrayList<>();
try {
for (Pair<Long, Integer> matchingData: matchingScoreList) { // 유사도가 높은 순서로 정렬한 후 반환
Optional<FindMatchingDto> findMatchingDto = this.getMatchingById(matchingData.getFirst());
findMatchingDto.ifPresent(sortedMatchingList::add);
FindMatchingDto findMatchingDto = this.getMatchingById(matchingData.getFirst());
if (findMatchingDto != null) {
sortedMatchingList.add(findMatchingDto);
}
}
} catch (Exception e) {
log.error("MatchingService::getRecommendedMatchingList: Cannot find matchingData");
Expand Down

0 comments on commit d4bbe7a

Please sign in to comment.