-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* feat: 반환된 예외를 통해 실패 원인을 찾는 기능 구현 * feat: 실패한 매칭 정보를 저장하는 엔티티 구현 * feat: 매칭을 실패했을 경우 실패한 매칭 정보를 저장하는 기능 구현 * refactor: 클래스명 변경 * feat: 반환된 예외를 통해 매칭 실패 원인에 대한 메세지를 얻는 기능 구현 * refactor: FailedMatching 생성자 변경 * feat: 매칭 실패한 방을 조회시, 실패 원인을 같이 전달하는 기능 구현 * refactor: 맵 구현체 변경 * refactor: 피드백 반영 --------- Co-authored-by: gyungchan Jo <[email protected]>
- Loading branch information
1 parent
5f5466f
commit 236675e
Showing
10 changed files
with
234 additions
and
16 deletions.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
backend/src/main/java/corea/matchresult/domain/FailedMatching.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package corea.matchresult.domain; | ||
|
||
import corea.exception.ExceptionType; | ||
import jakarta.persistence.*; | ||
import lombok.AccessLevel; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Entity | ||
@AllArgsConstructor | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@Getter | ||
public class FailedMatching { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
|
||
private long roomId; | ||
|
||
@Enumerated(EnumType.STRING) | ||
private MatchingFailedReason reason; | ||
|
||
public FailedMatching(long roomId, ExceptionType exceptionType) { | ||
this(null, roomId, MatchingFailedReason.from(exceptionType)); | ||
} | ||
|
||
public String getMatchingFailedReason() { | ||
return reason.getMessage(); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
backend/src/main/java/corea/matchresult/domain/MatchingFailedReason.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package corea.matchresult.domain; | ||
|
||
import corea.exception.ExceptionType; | ||
import lombok.Getter; | ||
|
||
import java.util.Arrays; | ||
|
||
@Getter | ||
public enum MatchingFailedReason { | ||
|
||
ROOM_NOT_FOUND(ExceptionType.ROOM_NOT_FOUND, "기존에 존재하던 방이 방장의 삭제로 인해 더 이상 유효하지 않아 매칭이 진행되지 않았습니다."), | ||
ROOM_STATUS_INVALID(ExceptionType.ROOM_STATUS_INVALID, "방이 이미 매칭 중이거나, 매칭이 완료되어 더 이상 매칭을 진행할 수 없는 상태입니다."), | ||
|
||
PARTICIPANT_SIZE_LACK(ExceptionType.PARTICIPANT_SIZE_LACK, "방의 최소 참여 인원보다 참가자가 부족하여 매칭이 진행되지 않았습니다."), | ||
PARTICIPANT_SIZE_LACK_DUE_TO_PULL_REQUEST(ExceptionType.PARTICIPANT_SIZE_LACK_DUE_TO_PULL_REQUEST, "참가자의 수는 최소 인원을 충족하였지만, 일부 참가자가 pull request를 제출하지 않아 매칭이 진행되지 않았습니다."), | ||
|
||
AUTOMATIC_MATCHING_NOT_FOUND(ExceptionType.AUTOMATIC_MATCHING_NOT_FOUND, "해당 방에 대해 예약된 자동 매칭 시간이 존재하지 않거나 설정되지 않아 매칭이 진행되지 않았습니다."), | ||
|
||
UNKNOWN(null, "매칭 과정에서 오류가 발생하여 매칭이 진행되지 않았습니다. 문제가 지속될 경우 관리자에게 문의하세요."), | ||
; | ||
|
||
private final ExceptionType exceptionType; | ||
private final String message; | ||
|
||
MatchingFailedReason(ExceptionType exceptionType, String message) { | ||
this.exceptionType = exceptionType; | ||
this.message = message; | ||
} | ||
|
||
public static MatchingFailedReason from(ExceptionType exceptionType) { | ||
return Arrays.stream(values()) | ||
.filter(reason -> reason.isTypeMatching(exceptionType)) | ||
.findAny() | ||
.orElse(UNKNOWN); | ||
} | ||
|
||
private boolean isTypeMatching(ExceptionType exceptionType) { | ||
return this.exceptionType == exceptionType; | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
backend/src/main/java/corea/matchresult/repository/FailedMatchingRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package corea.matchresult.repository; | ||
|
||
import corea.matchresult.domain.FailedMatching; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import java.util.Optional; | ||
|
||
public interface FailedMatchingRepository extends JpaRepository<FailedMatching, Long> { | ||
|
||
Optional<FailedMatching> findByRoomId(long roomId); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
backend/src/test/java/corea/matchresult/domain/MatchingFailedReasonTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package corea.matchresult.domain; | ||
|
||
import corea.exception.ExceptionType; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.CsvSource; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | ||
|
||
class MatchingFailedReasonTest { | ||
|
||
@ParameterizedTest | ||
@CsvSource(value = {"ROOM_NOT_FOUND, ROOM_NOT_FOUND", "AUTOMATIC_MATCHING_NOT_FOUND, AUTOMATIC_MATCHING_NOT_FOUND"}) | ||
@DisplayName("ExceptionType을 통해 매칭이 실패한 이유를 찾을 수 있다.") | ||
void from(ExceptionType exceptionType, MatchingFailedReason expected) { | ||
MatchingFailedReason actual = MatchingFailedReason.from(exceptionType); | ||
|
||
assertThat(actual).isEqualTo(expected); | ||
} | ||
|
||
@Test | ||
@DisplayName("ExceptionType을 통해 매칭 실패 이유를 찾을 수 없다면 UNKNOWN 반환한다.") | ||
void unknownReason() { | ||
MatchingFailedReason reason = MatchingFailedReason.from(ExceptionType.ALREADY_COMPLETED_FEEDBACK); | ||
|
||
assertThat(reason).isEqualTo(MatchingFailedReason.UNKNOWN); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.