Skip to content

Commit

Permalink
#42 좋아요 기능 코드 리팩토링
Browse files Browse the repository at this point in the history
  • Loading branch information
yujin-Jin committed Apr 4, 2022
1 parent c0edc5c commit c295379
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
8 changes: 0 additions & 8 deletions src/main/java/com/petpular/like/LikeRestController.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,6 @@ public Map<String, Object> like(

boolean existLike = likeBO.existLike(userId, postId);

if(existLike) {
// 좋아요가 활성화 되어있을 때 -> 좋아요 삭제
likeBO.deleteLike(userId, postId);
} else {
// 좋아요가 활성화 되어있지 않을 때 -> 좋아요 추가
likeBO.addLike(userId, postId);
}

result.put("like", existLike);
result.put("result", "success");

Expand Down
11 changes: 10 additions & 1 deletion src/main/java/com/petpular/like/bo/LikeBO.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,16 @@ public class LikeBO {
private LikeDAO likeDAO;

public boolean existLike(int userId, int postId) {
return likeDAO.existLike(userId, postId);
boolean existLike = likeDAO.existLike(userId, postId);

if(existLike) {
// 좋아요가 활성화 되어있을 때 -> 좋아요 삭제
deleteLike(userId, postId);
} else {
// 좋아요가 활성화 되어있지 않을 때 -> 좋아요 추가
addLike(userId, postId);
}
return existLike;
}

public int countLike(int postId) {
Expand Down

0 comments on commit c295379

Please sign in to comment.