From f53b1c42226c58e270592d194093b5d3fd88b66e Mon Sep 17 00:00:00 2001 From: hong Date: Fri, 22 Sep 2023 23:56:19 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20/member/delete=20=ED=97=88=EC=9A=A9=20?= =?UTF-8?q?=EB=A1=9C=EC=A7=81=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/Member/entity/Member.java | 3 +++ .../SummaryCode/controller/SummaryCodeController.java | 7 +++++++ .../repository/ScrapSummaryCodeRepository.java | 2 ++ .../domain/SummaryCode/service/SummaryService.java | 9 ++++++++- 4 files changed, 20 insertions(+), 1 deletion(-) 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); + } }