Skip to content

Commit

Permalink
feat: 친구 요청 시 중복 검증 로직 추가 (#52)
Browse files Browse the repository at this point in the history
  • Loading branch information
kyeong-hyeok committed Sep 28, 2023
1 parent a0cfbde commit afb6b11
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public class FriendRequestController {
responses = {
@ApiResponse(responseCode = "204", description = "친구 요청 성공")
, @ApiResponse(responseCode = "401", description = "인증에 실패했습니다.")
, @ApiResponse(responseCode = "400", description = "이미 보낸 친구 요청입니다.")
, @ApiResponse(responseCode = "404", description = "해당 회원을 찾을 수 없습니다.", content = @Content(schema = @Schema(implementation = ErrorResponse.class)))
})
@PostMapping("/{memberId}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ public class FriendRequestService {
public void saveFriendRequest(String email, Long friendId) {
Member member = memberRepository.findByEmail(email).orElseThrow(() -> new BusinessException(ErrorCode.MEMBER_NOT_FOUND));
Member friend = memberRepository.findById(friendId).orElseThrow(() -> new BusinessException(ErrorCode.MEMBER_NOT_FOUND));
if (friendRequestRepository.findByFromMemberAndToMember(member, friend).isPresent())
throw new BusinessException(ErrorCode.ALREADY_EXIST_FRIEND_REQUEST);
friendRequestRepository.save(new FriendRequest(member, friend));
}

Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/project/mapdagu/error/ErrorCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ public enum ErrorCode {
EMAIL_SEND_ERROR(BAD_REQUEST, "이메일 인증 코드 전송을 실패했습니다."),
ALREADY_EXIST_EMAIL(BAD_REQUEST, "이미 존재하는 이메일입니다."),
ALREADY_EXIST_USERNAME(BAD_REQUEST, "이미 존재하는 사용자 이름입니다."),
ALREADY_EXIST_FRIEND(BAD_REQUEST, "이미 상대방과 친구입니다.");
ALREADY_EXIST_FRIEND(BAD_REQUEST, "이미 상대방과 친구입니다."),
ALREADY_EXIST_FRIEND_REQUEST(BAD_REQUEST, "이미 보낸 친구 요청입니다.");

private final int code;
private final String message;
Expand Down

0 comments on commit afb6b11

Please sign in to comment.