diff --git a/src/main/java/codingFriends_Server/domain/Member/entity/Member.java b/src/main/java/codingFriends_Server/domain/Member/entity/Member.java index 1f591f9..544872d 100644 --- a/src/main/java/codingFriends_Server/domain/Member/entity/Member.java +++ b/src/main/java/codingFriends_Server/domain/Member/entity/Member.java @@ -1,5 +1,6 @@ package codingFriends_Server.domain.Member.entity; +import codingFriends_Server.domain.SummaryCode.entity.ScrapSummaryCode; import codingFriends_Server.domain.SummaryCode.entity.SummaryCode; import codingFriends_Server.global.auth.oauth.LoginProvider; import lombok.*; @@ -38,6 +39,8 @@ public class Member implements UserDetails { @OneToMany(mappedBy = "member", cascade = CascadeType.REMOVE) private List summaryCodeList = new ArrayList<>(); + @OneToMany(mappedBy = "member", cascade = CascadeType.REMOVE) + private List scrapSummaryCodes = new ArrayList<>(); @Override public Collection getAuthorities() { List authorities = new ArrayList<>(); diff --git a/src/main/java/codingFriends_Server/domain/SummaryCode/controller/SummaryCodeController.java b/src/main/java/codingFriends_Server/domain/SummaryCode/controller/SummaryCodeController.java index 331f8e3..5e43a24 100644 --- a/src/main/java/codingFriends_Server/domain/SummaryCode/controller/SummaryCodeController.java +++ b/src/main/java/codingFriends_Server/domain/SummaryCode/controller/SummaryCodeController.java @@ -104,4 +104,11 @@ public ResponseEntity deleteSummaryCode(@PathVariable Long id) { return ResponseEntity.ok() .body("summaryCode 삭제 완료"); } + + @DeleteMapping("ai/summary/delete/scrap/{id}") + public ResponseEntity deleteScrapSummaryCode(@PathVariable Long id) { + summaryService.deleteScrapSummaryCode(id); + return ResponseEntity.ok() + .body("ScrapSummaryCode 삭제 완료"); + } } diff --git a/src/main/java/codingFriends_Server/domain/SummaryCode/repository/ScrapSummaryCodeRepository.java b/src/main/java/codingFriends_Server/domain/SummaryCode/repository/ScrapSummaryCodeRepository.java index 72896e9..7346adf 100644 --- a/src/main/java/codingFriends_Server/domain/SummaryCode/repository/ScrapSummaryCodeRepository.java +++ b/src/main/java/codingFriends_Server/domain/SummaryCode/repository/ScrapSummaryCodeRepository.java @@ -12,4 +12,6 @@ public interface ScrapSummaryCodeRepository extends JpaRepository findScrapSummaryCodeByCreatedAt(LocalDateTime localDateTime); List findScrapSummaryCodesByMemberOrderByCreatedAtDesc(Member member); + + Optional findScrapSummaryCodeById(Long id); } diff --git a/src/main/java/codingFriends_Server/domain/SummaryCode/service/SummaryService.java b/src/main/java/codingFriends_Server/domain/SummaryCode/service/SummaryService.java index dfe1a35..5b56c71 100644 --- a/src/main/java/codingFriends_Server/domain/SummaryCode/service/SummaryService.java +++ b/src/main/java/codingFriends_Server/domain/SummaryCode/service/SummaryService.java @@ -113,7 +113,14 @@ public List getScrapSummaryContents(Member member) { } public void deleteSummaryCode(Long id) { - SummaryCode summaryCode = summaryCodeRepository.findSummaryCodeById(id).orElseThrow(() -> new CustomException(HttpStatus.NOT_FOUND, "summaryCode를 찾을 수 없습니다.")); + SummaryCode summaryCode = summaryCodeRepository.findSummaryCodeById(id).orElseThrow( + () -> new CustomException(HttpStatus.NOT_FOUND, "summaryCode를 찾을 수 없습니다.")); summaryCodeRepository.delete(summaryCode); } + + public void deleteScrapSummaryCode(Long id) { + ScrapSummaryCode scrapSummaryCode = scrapSummaryCodeRepository.findScrapSummaryCodeById(id).orElseThrow( + () -> new CustomException(HttpStatus.NOT_FOUND, "ScrapSummaryCode를 찾을 수 없습니다.")); + scrapSummaryCodeRepository.delete(scrapSummaryCode); + } }