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); + } }