Skip to content

Commit

Permalink
Merge pull request #64 from DongnaeFriend/feature/#56
Browse files Browse the repository at this point in the history
✨ Feat #56 : 스크랩 삭제 기능 추가
  • Loading branch information
Suanna01 authored Aug 4, 2023
2 parents 5b46335 + 4f3474b commit 7cebe44
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,8 @@ public interface ScrapRepository extends JpaRepository<Scrap, Long> {
SharingBoard findBySharingBoardId(@Param("sharing_board_id") Long sharing_board_id);
@Query("SELECT db FROM DongnaeBoard db WHERE db.id = :dongnae_board_id")
DongnaeBoard findByDongnaeBoardId(@Param("dongnae_board_id") Long dongnae_board_id);
@Query(value = "SELECT scrap.* FROM scrap WHERE scrap.sharing_board_id = :sharing_board_id", nativeQuery = true)
Scrap findBySharingBoardId(@Param("sharing_board_id") SharingBoard sharing_board_id);
@Query(value = "SELECT scrap.* FROM scrap WHERE scrap.dongnae_board_id = :dongnae_board_id", nativeQuery = true)
Scrap findByDongnaeBoardId(@Param("dongnae_board_id") DongnaeBoard dongnae_board_id);
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,42 @@ public String newScrap(ReqScrapDto reqScrapDto) {
if (!(reqScrapDto.getAccountBookId() == null)) {
SharingBoard sharingBoard = scrapRepository.findBySharingBoardId(reqScrapDto.getAccountBookId());

// 스크랩 정보 저장
Scrap scrap = Scrap.builder()
.sharingBoard(sharingBoard)
.user(user)
.build();
// 스크랩 여부
Scrap scrapExist = scrapRepository.findBySharingBoardId(sharingBoard);

scrapRepository.save(scrap);
if (scrapExist == null) {
// 스크랩 정보 저장
Scrap scrap = Scrap.builder()
.sharingBoard(sharingBoard)
.user(user)
.build();

scrapRepository.save(scrap);
}
else {
scrapRepository.delete(scrapExist);
}
}

// 동네정보
else if (!(reqScrapDto.getTownInformationId() == null)) {
DongnaeBoard dongnaeBoard = scrapRepository.findByDongnaeBoardId(reqScrapDto.getTownInformationId());

// 스크랩 정보 저장
Scrap scrap = Scrap.builder()
.dongnaeBoard(dongnaeBoard)
.user(user)
.build();
// 스크랩 여부
Scrap scrapExist = scrapRepository.findByDongnaeBoardId(dongnaeBoard);

if (scrapExist == null) {
// 스크랩 정보 저장
Scrap scrap = Scrap.builder()
.dongnaeBoard(dongnaeBoard)
.user(user)
.build();

scrapRepository.save(scrap);
scrapRepository.save(scrap);
}
else {
scrapRepository.delete(scrapExist);
}
}

else {
Expand Down

0 comments on commit 7cebe44

Please sign in to comment.