Skip to content

Commit

Permalink
feat: 친구 추가 시 현재 상대방과 친구인지 확인하는 로직 추가 (#51)
Browse files Browse the repository at this point in the history
  • Loading branch information
kyeong-hyeok committed Sep 28, 2023
1 parent 1893d5b commit a0cfbde
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ public ResponseEntity<SliceResponseDto> searchMember(@AuthenticationPrincipal Us
responses = {
@ApiResponse(responseCode = "204", description = "친구 추가 성공")
, @ApiResponse(responseCode = "401", description = "인증에 실패했습니다.")
, @ApiResponse(responseCode = "404", description = "해당 회원을 찾을 수 없습니다.", content = @Content(schema = @Schema(implementation = ErrorResponse.class)))
, @ApiResponse(responseCode = "400", description = "이미 상대방과 친구입니다.")
, @ApiResponse(responseCode = "404", description = "1. 해당 회원을 찾을 수 없습니다. \t\n 2. 해당 친구 요청을 찾을 수 없습니다.", content = @Content(schema = @Schema(implementation = ErrorResponse.class)))
})
@PostMapping("/{memberId}")
public ResponseEntity<Void> saveFriend(@AuthenticationPrincipal UserDetails loginUser, @PathVariable Long memberId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ public Slice<FriendSearchResponseDto> searchMember(String email, String search,
public void saveFriend(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 (friendRepository.findByMemberAndFriend(member, friend).isPresent() || friendRepository.findByMemberAndFriend(friend, member).isPresent())
throw new BusinessException(ErrorCode.ALREADY_EXIST_FRIEND);
FriendRequest friendRequest = friendRequestRepository.findByFromMemberAndToMember(friend, member).orElseThrow(() -> new BusinessException(ErrorCode.FRIEND_REQUEST_NOT_FOUND));
friendRequestRepository.delete(friendRequest);
friendRepository.save(new Friend(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 @@ -25,7 +25,8 @@ public enum ErrorCode {
ALREADY_LOGOUT_MEMBER(BAD_REQUEST, "이미 로그아웃한 회원입니다"),
EMAIL_SEND_ERROR(BAD_REQUEST, "이메일 인증 코드 전송을 실패했습니다."),
ALREADY_EXIST_EMAIL(BAD_REQUEST, "이미 존재하는 이메일입니다."),
ALREADY_EXIST_USERNAME(BAD_REQUEST, "이미 존재하는 사용자 이름입니다.");
ALREADY_EXIST_USERNAME(BAD_REQUEST, "이미 존재하는 사용자 이름입니다."),
ALREADY_EXIST_FRIEND(BAD_REQUEST, "이미 상대방과 친구입니다.");

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

0 comments on commit a0cfbde

Please sign in to comment.