Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ public enum ErrorCode implements BaseCode {
TID_NOT_EXIST(HttpStatus.BAD_REQUEST, "PAYMENT_4001", "tid가 존재하지 않습니다."),
TID_SID_UNSUPPORTED(HttpStatus.BAD_REQUEST, "PAYMENT_4002", "지원되지 않는 tid, sid 입니다."),
SID_NOT_EXIST(HttpStatus.BAD_REQUEST, "PAYMENT_4003", "sid가 존재하지 않습니다."),

// Match
MATCH_NOT_EXIST(HttpStatus.BAD_REQUEST, "MATCH_4001", "매치 신청 정보가 존재하지 않습니다."),
;

private final HttpStatus httpStatus;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public enum SuccessCode implements BaseCode {

// MatchRequest
MATCH_REQUEST_SUCCESS(HttpStatus.OK, "MATCH_REQUEST_2001", "매치 신청이 완료되었습니다."),
MATCH_VIEW_REQUEST_RESULT_SUCCESS(HttpStatus.OK, "MATCH_REQUEST_2001", "매치 신청 결과 반환 완료되었습니다."),

// Payment
PAYMENT_URL_CREATE_SUCCESS(HttpStatus.OK, "PAYMENT_2001", "카카오페이 URL을 생성하였습니다."),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,14 @@ public ApiResponse<Boolean> matchRequest(

return ApiResponse.onSuccess(SuccessCode.MATCH_REQUEST_SUCCESS, true);
}
@PostMapping("/results")
public ApiResponse<Boolean> matchRequestResult(
@AuthenticationPrincipal CustomUserDetails customUserDetails
) {
User user = userService.findByUserName(customUserDetails.getUsername());

boolean isNotMatched = matchingService.checkMatchRequest(user);

return ApiResponse.onSuccess(SuccessCode.MATCH_VIEW_REQUEST_RESULT_SUCCESS, !isNotMatched);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,16 @@
import org.springframework.data.repository.query.Param;

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

public interface MatchingRepository extends JpaRepository<MatchRequest, Long> {

@Query("SELECT m FROM MatchRequest m JOIN FETCH m.user WHERE m.status = :status ORDER BY m.createdAt ASC")
List<MatchRequest> findAllWithUserByStatus(@Param("status") MatchStatus status);

boolean existsByUser_IdAndStatus(Long userId, MatchStatus status);

boolean existsByUser_Id(Long userId);

Optional<MatchRequest> findByUser_Id(Long userId);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.example.silverbridgeX_user.matching.service;

import com.example.silverbridgeX_user.global.api_payload.ErrorCode;
import com.example.silverbridgeX_user.global.exception.GeneralException;
import com.example.silverbridgeX_user.matching.algorithm.AdjacencyGraphBuilder;
import com.example.silverbridgeX_user.matching.algorithm.Matcher;
import com.example.silverbridgeX_user.matching.converter.MatchingConverter;
Expand Down Expand Up @@ -29,15 +31,27 @@ public class MatchingService {
private String chatServerUrl;

private final MatchingRepository matchingRepository;
private final UserRepository userRepository;

@Transactional
public void saveMatchRequest(User user) {
MatchRequest matchRequest = MatchingConverter.toMatchRequest(user);
MatchRequest matchRequest;

if (matchingRepository.existsByUser_Id(user.getId())) {
matchRequest = matchingRepository.findByUser_Id(user.getId()).orElseThrow(() -> new GeneralException(ErrorCode.MATCH_NOT_EXIST));
matchRequest.updateStatus(MatchStatus.WAITING);
}
else {
matchRequest = MatchingConverter.toMatchRequest(user);
}

matchingRepository.save(matchRequest);
}

@Transactional
public boolean checkMatchRequest(User user) {

return matchingRepository.existsByUser_IdAndStatus(user.getId(), MatchStatus.WAITING);
}

@Transactional
public void executeMatchingAlgorithm() {
Expand Down