Skip to content

Commit

Permalink
Fix: 댓글, 대댓글 달 때 반려동물 있는지 확인하는 로직 추가
Browse files Browse the repository at this point in the history
Fix: 댓글, 대댓글 달 때 반려동물 있는지 확인하는 로직 추가
  • Loading branch information
seoyeonjin authored Jan 21, 2025
2 parents 46b4d1f + bacb247 commit c92af31
Showing 1 changed file with 10 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ public class CommentService {
@Transactional
public void addPostComment(final Long postId, final String content, final Long memberId) {
validatePostExists(postId);
validatePet(memberId);

commentRepository.save(
Comment.builder()
.content(content)
Expand All @@ -65,6 +67,8 @@ public void addPostSubComment(final Long commentId, final Long mentionedMemberId
if (!memberRepository.existsById(mentionedMemberId)) {
throw new CocosException(FailMessage.NOT_FOUND_MENTIONED_MEMBER);
}

validatePet(memberId);
subCommentRepository.save(
SubComment.builder()
.commentId(commentId)
Expand Down Expand Up @@ -200,6 +204,12 @@ public MyAllCommentsResponse getMyComments(final String nickname, final Long mem
);
}

private void validatePet(Long memberId) {
if (!petRepository.existsByMemberId(memberId)) {
throw new CocosException(FailMessage.NOT_FOUND_PET);
}
}

private Comment validateCommentExists(Long commentId) {
return commentRepository.findById(commentId).orElseThrow(
() -> new CocosException(FailMessage.NOT_FOUND_COMMENT)
Expand Down

0 comments on commit c92af31

Please sign in to comment.