Skip to content

Commit

Permalink
Merge pull request #26 from team-nabi/NABI-122--junhyuk--feat--delete…
Browse files Browse the repository at this point in the history
…-own-card

NABI-122--feat : 사용자 본인의 카드 삭제
  • Loading branch information
hi-june authored Nov 10, 2023
2 parents 99917fb + a20230b commit 9d9d96e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -87,4 +90,14 @@ public ResponseEntity<SingleResult<CardListResponseDTO<SuggestionAvailableCardRe

return ResponseEntity.ok(ResponseFactory.getSingleResult(cardListResponseDTO));
}

@DeleteMapping("/{cardId}")
public ResponseEntity<CommonResult> deleteCardById(
@RequestHeader(name = "authorization") String token,
@PathVariable Long cardId
) {
cardService.deleteCardById(token, cardId);

return ResponseEntity.ok(ResponseFactory.getSuccessResult());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -185,4 +187,19 @@ public CardListResponseDTO<SuggestionAvailableCardResponseDTO> 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));

if (!checkService.isEqual(token, card.getUser().getUserId())) {
throw new BaseException(ErrorCode.USER_NOT_MATCHED);
}

cardRepository.delete(card);
}
}

0 comments on commit 9d9d96e

Please sign in to comment.