Skip to content

Commit

Permalink
feat: 친구 요청 삭제 기능 구현 (#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
kyeong-hyeok committed Sep 17, 2023
1 parent e13da3d commit f5b59d9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;

@Tag(name = "Friend Request", description = "Friend Request API")
@RestController
Expand All @@ -38,4 +35,17 @@ public ResponseEntity<Void> saveFriendRequest(@AuthenticationPrincipal UserDetai
friendRequestService.saveFriendRequest(loginUser.getUsername(), friendId);
return ResponseDto.noContent();
}

@Operation(summary = "친구 요청 삭제", description = "친구 요청을 삭제합니다.",
security = { @SecurityRequirement(name = "bearer-key") },
responses = {
@ApiResponse(responseCode = "200", description = "친구 요청 삭제 성공")
, @ApiResponse(responseCode = "401", description = "인증에 실패했습니다.")
, @ApiResponse(responseCode = "404", description = "해당 회원을 찾을 수 없습니다.", content = @Content(schema = @Schema(implementation = ErrorResponse.class)))
})
@DeleteMapping("/{friendId}")
public ResponseEntity<Void> deleteFriendRequest(@AuthenticationPrincipal UserDetails loginUser, @PathVariable Long friendId) {
friendRequestService.deleteFriendRequest(loginUser.getUsername(), friendId);
return ResponseDto.noContent();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,11 @@ public void saveFriendRequest(String email, Long friendId) {
Member friend = memberRepository.findById(friendId).orElseThrow(() -> new BusinessException(ErrorCode.MEMBER_NOT_FOUND));
friendRequestRepository.save(new FriendRequest(member, friend));
}

public void deleteFriendRequest(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));
FriendRequest friendRequest = friendRequestRepository.findByFromMemberAndToMember(member, friend).orElseThrow(() -> new BusinessException(ErrorCode.FRIEND_REQUEST_NOT_FOUND));
friendRequestRepository.delete(friendRequest);
}
}

0 comments on commit f5b59d9

Please sign in to comment.