From a16cdc81fa8185dbf2e5cf6e4da12de00b0757e8 Mon Sep 17 00:00:00 2001 From: swa07016 Date: Sat, 7 Oct 2023 17:50:33 +0900 Subject: [PATCH] =?UTF-8?q?:recycle:=20Refactor:=20scrap=EC=82=AD=EC=A0=9C?= =?UTF-8?q?=20API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 파라미터를 변경했습니다. --- src/main/java/briefing/scrap/api/ScrapApi.java | 6 +++--- .../briefing/scrap/application/ScrapCommandService.java | 4 ++-- .../briefing/scrap/domain/repository/ScrapRepository.java | 3 +++ 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/main/java/briefing/scrap/api/ScrapApi.java b/src/main/java/briefing/scrap/api/ScrapApi.java index 4546309..3761c4a 100644 --- a/src/main/java/briefing/scrap/api/ScrapApi.java +++ b/src/main/java/briefing/scrap/api/ScrapApi.java @@ -29,9 +29,9 @@ public CommonResponse create(@RequestBody ScrapRequest. } @Operation(summary = "05-02 Scrap📁 스크랩 취소 #FRAME", description = "스크랩을 취소하는 API입니다.") - @DeleteMapping("/{scrapId}") - public CommonResponse delete(@PathVariable Long scrapId) { - Scrap deletedScrap = scrapCommandService.delete(scrapId); + @DeleteMapping("/briefings/{briefingId}/members/{memberId}") + public CommonResponse delete(@PathVariable Long briefingId, @PathVariable Long memberId) { + Scrap deletedScrap = scrapCommandService.delete(briefingId, memberId); return CommonResponse.onSuccess(ScrapConverter.toDeleteDTO(deletedScrap)); } diff --git a/src/main/java/briefing/scrap/application/ScrapCommandService.java b/src/main/java/briefing/scrap/application/ScrapCommandService.java index 1b8cb9d..bcbea3c 100644 --- a/src/main/java/briefing/scrap/application/ScrapCommandService.java +++ b/src/main/java/briefing/scrap/application/ScrapCommandService.java @@ -43,8 +43,8 @@ public Scrap create(ScrapRequest.CreateDTO request) { return scrapRepository.save(scrap); } - public Scrap delete(Long scrapId) { - Scrap scrap = scrapRepository.findById(scrapId) + public Scrap delete(Long briefingId, Long memberId) { + Scrap scrap = scrapRepository.findByBriefing_IdAndMember_Id(briefingId, memberId) .orElseThrow(() -> new ScrapException(ErrorCode.SCRAP_NOT_FOUND)); scrapRepository.delete(scrap); return scrap; diff --git a/src/main/java/briefing/scrap/domain/repository/ScrapRepository.java b/src/main/java/briefing/scrap/domain/repository/ScrapRepository.java index 66a09e1..9acdad4 100644 --- a/src/main/java/briefing/scrap/domain/repository/ScrapRepository.java +++ b/src/main/java/briefing/scrap/domain/repository/ScrapRepository.java @@ -4,9 +4,12 @@ import org.springframework.data.jpa.repository.JpaRepository; import java.util.List; +import java.util.Optional; public interface ScrapRepository extends JpaRepository { + Optional findByBriefing_IdAndMember_Id(Long briefingId, Long memberId); + boolean existsByMember_IdAndBriefing_Id(Long memberId, Long briefingId); List findByMember_Id(Long memberId);