Skip to content

Commit

Permalink
[Refactor] 본인 글에 추천 금지
Browse files Browse the repository at this point in the history
  • Loading branch information
hen715 committed Mar 28, 2024
1 parent 4bc0d84 commit 6d9f147
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ public enum MyErrorCode {
WRONG_SEARCH_TYPE(HttpStatus.BAD_REQUEST,"검색옵션이 올바르지 않습니다."),
EMPTY_REQUEST(HttpStatus.BAD_REQUEST,"닉네임, 횃불이 아이디 모두 공백입니다."),
NOT_BLANK_NICKNAME(HttpStatus.BAD_REQUEST,"닉네임이 빈칸 혹은 공백입니다."),
EMAIL_NOT_AUTHORIZATION(HttpStatus.FORBIDDEN,"인증되지 않은 이메일입니다.");
EMAIL_NOT_AUTHORIZATION(HttpStatus.FORBIDDEN,"인증되지 않은 이메일입니다."),
NOT_LIKE_MY_POST(HttpStatus.BAD_REQUEST,"자신의 게시글에는 추천을 할 수 없습니다."),
NOT_LIKE_MY_REPLY(HttpStatus.BAD_REQUEST,"자신의 댓글에는 추천을 할 수 없습니다.");


private final HttpStatus status;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,9 @@ else if(sort.equals("scrap")){
@Transactional
public int likePost(Member member, Long postId){
Post post = postRepository.findByIdWithLock(postId).orElseThrow(()->new MyException(MyErrorCode.POST_NOT_FOUND));
if(post.getMember()!=null&&post.getMember().getId().equals(member.getId())){
throw new MyException(MyErrorCode.NOT_LIKE_MY_POST);
}
if(likePostRepository.existsByMemberAndPost(member,post)){
PostLike postLike = likePostRepository.findByMemberAndPost(member,post).orElseThrow(()->new MyException(MyErrorCode.USER_OR_POST_NOT_FOUND));
likePostRepository.delete(postLike);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ public void delete(Long memberId, Long replyId){
@Transactional
public int likeReply(Member member, Long replyId){
Reply reply = replyRepository.findById(replyId).orElseThrow(()->new MyException(MyErrorCode.REPLY_NOT_FOUND));
if(reply.getMember()!=null&&reply.getMember().getId().equals(member.getId())){
throw new MyException(MyErrorCode.NOT_LIKE_MY_REPLY);
}
if(likeReplyRepository.existsByMemberAndReply(member,reply)){
ReplyLike replyLike = likeReplyRepository.findByMemberAndReply(member,reply).orElseThrow(()->new MyException(MyErrorCode.USER_OR_REPLY_NOT_FOUND));
likeReplyRepository.delete(replyLike);
Expand Down

0 comments on commit 6d9f147

Please sign in to comment.