From 2c235a703d8cabb944c718a2cc6e554246ff34f0 Mon Sep 17 00:00:00 2001 From: hi-june Date: Thu, 9 Nov 2023 20:54:49 +0900 Subject: [PATCH 1/2] =?UTF-8?q?NABI-122--feat=20:=20=EC=82=AC=EC=9A=A9?= =?UTF-8?q?=EC=9E=90=20=EB=B3=B8=EC=9D=B8=EC=9D=98=20=EC=B9=B4=EB=93=9C=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/card/api/CardController.java | 13 +++++++++++++ .../domain/card/service/CardService.java | 15 +++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/src/main/java/org/prgrms/nabimarketbe/domain/card/api/CardController.java b/src/main/java/org/prgrms/nabimarketbe/domain/card/api/CardController.java index 93d2d504..3a1000c1 100644 --- a/src/main/java/org/prgrms/nabimarketbe/domain/card/api/CardController.java +++ b/src/main/java/org/prgrms/nabimarketbe/domain/card/api/CardController.java @@ -5,12 +5,15 @@ import org.prgrms.nabimarketbe.domain.card.dto.request.CardCreateRequestDTO; import org.prgrms.nabimarketbe.domain.card.dto.response.CardCreateResponseDTO; import org.prgrms.nabimarketbe.domain.card.dto.response.CardListReadPagingResponseDTO; +import org.prgrms.nabimarketbe.domain.card.dto.response.CardListResponseDTO; import org.prgrms.nabimarketbe.domain.card.dto.response.CardSingleReadResponseDTO; +import org.prgrms.nabimarketbe.domain.card.dto.response.SuggestionAvailableCardResponseDTO; import org.prgrms.nabimarketbe.domain.card.entity.CardStatus; import org.prgrms.nabimarketbe.domain.card.service.CardService; import org.prgrms.nabimarketbe.domain.category.entity.CategoryEnum; import org.prgrms.nabimarketbe.domain.item.entity.PriceRange; import org.prgrms.nabimarketbe.global.util.ResponseFactory; +import org.prgrms.nabimarketbe.global.util.model.CommonResult; import org.prgrms.nabimarketbe.global.util.model.SingleResult; import org.springframework.http.MediaType; @@ -87,4 +90,14 @@ public ResponseEntity deleteCardById( + @RequestHeader(name = "authorization") String token, + @PathVariable Long cardId + ) { + cardService.deleteCardById(token, cardId); + + return ResponseEntity.ok(ResponseFactory.getSuccessResult()); + } } diff --git a/src/main/java/org/prgrms/nabimarketbe/domain/card/service/CardService.java b/src/main/java/org/prgrms/nabimarketbe/domain/card/service/CardService.java index 4889958a..c6bd8697 100644 --- a/src/main/java/org/prgrms/nabimarketbe/domain/card/service/CardService.java +++ b/src/main/java/org/prgrms/nabimarketbe/domain/card/service/CardService.java @@ -6,7 +6,9 @@ import org.prgrms.nabimarketbe.domain.card.dto.request.CardCreateRequestDTO; import org.prgrms.nabimarketbe.domain.card.dto.response.CardCreateResponseDTO; import org.prgrms.nabimarketbe.domain.card.dto.response.CardListReadPagingResponseDTO; +import org.prgrms.nabimarketbe.domain.card.dto.response.CardListResponseDTO; import org.prgrms.nabimarketbe.domain.card.dto.response.CardSingleReadResponseDTO; +import org.prgrms.nabimarketbe.domain.card.dto.response.SuggestionAvailableCardResponseDTO; import org.prgrms.nabimarketbe.domain.card.entity.Card; import org.prgrms.nabimarketbe.domain.card.entity.CardStatus; import org.prgrms.nabimarketbe.domain.card.repository.CardRepository; @@ -185,4 +187,17 @@ public CardListResponseDTO getSuggestionAvai return new CardListResponseDTO<>(cardListResponse); } + + @Transactional + public void deleteCardById( + String token, + Long cardId + ) { + Card card = cardRepository.findById(cardId) + .orElseThrow(() -> new BaseException(ErrorCode.CARD_NOT_FOUND)); + + checkService.isEqual(token, card.getUser().getUserId()); + + cardRepository.delete(card); + } } From a20230b18a08343c926c34c0b617a893adc67842 Mon Sep 17 00:00:00 2001 From: hi-june Date: Fri, 10 Nov 2023 16:34:16 +0900 Subject: [PATCH 2/2] =?UTF-8?q?NABI-122--refactor=20:=20=EC=B9=B4=EB=93=9C?= =?UTF-8?q?=20=EC=A3=BC=EC=9D=B8=EC=9D=B4=20=EB=A7=9E=EC=A7=80=20=EC=95=8A?= =?UTF-8?q?=EC=9D=84=20=EC=8B=9C=20=EC=98=88=EC=99=B8=20=EB=B0=9C=EC=83=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../prgrms/nabimarketbe/domain/card/service/CardService.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/prgrms/nabimarketbe/domain/card/service/CardService.java b/src/main/java/org/prgrms/nabimarketbe/domain/card/service/CardService.java index c6bd8697..3bebe4dc 100644 --- a/src/main/java/org/prgrms/nabimarketbe/domain/card/service/CardService.java +++ b/src/main/java/org/prgrms/nabimarketbe/domain/card/service/CardService.java @@ -196,7 +196,9 @@ public void deleteCardById( Card card = cardRepository.findById(cardId) .orElseThrow(() -> new BaseException(ErrorCode.CARD_NOT_FOUND)); - checkService.isEqual(token, card.getUser().getUserId()); + if (!checkService.isEqual(token, card.getUser().getUserId())) { + throw new BaseException(ErrorCode.USER_NOT_MATCHED); + } cardRepository.delete(card); }