Skip to content

Commit

Permalink
✨ Feat #57 : [가계부 공유] 공감 삭제 기능 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
Suanna01 committed Aug 4, 2023
1 parent e2ce8d5 commit b0a6149
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ public interface SharingSympathyRepository extends JpaRepository<SharingSympathy
User findByUserId(@Param("user_id") Long user_id);
@Query("SELECT sb FROM SharingBoard sb WHERE sb.id = :sharing_board_id")
SharingBoard findBySharingBoardId(@Param("sharing_board_id") Long sharing_board_id);
@Query(value = "SELECT sharing_sympathy.* FROM sharing_sympathy WHERE sharing_sympathy.sharing_board_id = :sharing_board_id", nativeQuery = true)
SharingSympathy findBySharingBoardId(@Param("sharing_board_id") SharingBoard sharing_board_id);


int countAllBySharingBoardId(Long sharing_board_id);
int countAllByUserId(Long userId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,25 @@ public String newSympathy(Long accountBookId){
// 게시판 가져오기
SharingBoard sharingBoard = sharingSympathyRepository.findBySharingBoardId(accountBookId);

// 공감 데이터 저장하기
SharingSympathy sharingSympathy = SharingSympathy.builder()
.sharingBoard(sharingBoard)
.user(user)
.build();
// 공감 유무 확인하기
SharingSympathy sharingSympathyExist = sharingSympathyRepository.findBySharingBoardId(sharingBoard);

sharingSympathyRepository.save(sharingSympathy);
if (sharingSympathyExist == null) {
// 공감 데이터 저장하기
SharingSympathy sharingSympathy = SharingSympathy.builder()
.sharingBoard(sharingBoard)
.user(user)
.build();

return "[가계부 공유] 공감 성공";
sharingSympathyRepository.save(sharingSympathy);

return "[가계부 공유] 공감 성공";
}

// 공감 데이터 삭제하기
sharingSympathyRepository.delete(sharingSympathyExist);

return "[가계부 공유] 공감 삭제 성공";
}

}

0 comments on commit b0a6149

Please sign in to comment.