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 253bce3c..26c9d652 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 @@ -3,6 +3,7 @@ import lombok.RequiredArgsConstructor; import org.prgrms.nabimarketbe.domain.card.dto.request.CardCreateRequestDTO; +import org.prgrms.nabimarketbe.domain.card.dto.request.CardStatusUpdateRequestDTO; 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; @@ -91,6 +92,20 @@ public ResponseEntity updateCardStatusById( + @RequestHeader(name = "authorization") String token, + @PathVariable Long cardId, + @RequestBody CardStatusUpdateRequestDTO cardStatusUpdateRequestDTO + ) { + cardService.updateCardStatusById( + token, + cardId, + cardStatusUpdateRequestDTO + ); + + return ResponseEntity.ok(ResponseFactory.getSuccessResult()); + @GetMapping("/{status}/my-cards") public ResponseEntity> getMyCardsByStatus( @RequestHeader(name = "authorization") String token, diff --git a/src/main/java/org/prgrms/nabimarketbe/domain/card/dto/request/CardStatusUpdateRequestDTO.java b/src/main/java/org/prgrms/nabimarketbe/domain/card/dto/request/CardStatusUpdateRequestDTO.java new file mode 100644 index 00000000..8dc97fba --- /dev/null +++ b/src/main/java/org/prgrms/nabimarketbe/domain/card/dto/request/CardStatusUpdateRequestDTO.java @@ -0,0 +1,10 @@ +package org.prgrms.nabimarketbe.domain.card.dto.request; + +import org.prgrms.nabimarketbe.domain.card.entity.CardStatus; +import org.prgrms.nabimarketbe.global.annotation.ValidEnum; + +public record CardStatusUpdateRequestDTO( + @ValidEnum(enumClass = CardStatus.class, message = "유효하지 않은 상태입니다.") + CardStatus cardStatus +) { +} diff --git a/src/main/java/org/prgrms/nabimarketbe/domain/card/entity/Card.java b/src/main/java/org/prgrms/nabimarketbe/domain/card/entity/Card.java index c052178c..da10afa9 100644 --- a/src/main/java/org/prgrms/nabimarketbe/domain/card/entity/Card.java +++ b/src/main/java/org/prgrms/nabimarketbe/domain/card/entity/Card.java @@ -130,4 +130,16 @@ public void increaseDibCount() { public void decreaseDibCount() { this.dibCount -= 1; } + + public void updateCardStatusToTradeAvailable() { + this.status = CardStatus.TRADE_AVAILABLE; + } + + public void updateCardStatusToReserved() { + this.status = CardStatus.RESERVED; + } + + public void updateCardStatusToTradeComplete() { + this.status = CardStatus.TRADE_COMPLETE; + } } 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 a98ffe6f..91503154 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 @@ -4,6 +4,7 @@ import java.util.List; import org.prgrms.nabimarketbe.domain.card.dto.request.CardCreateRequestDTO; +import org.prgrms.nabimarketbe.domain.card.dto.request.CardStatusUpdateRequestDTO; 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; @@ -206,6 +207,26 @@ public CardListReadPagingResponseDTO getMyCardsByStatus( ); } + @Transactional + public void updateCardStatusById( + String token, + Long cardId, + CardStatusUpdateRequestDTO cardStatusUpdateRequestDTO + ) { + 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); + } + + switch (cardStatusUpdateRequestDTO.cardStatus()) { + case TRADE_AVAILABLE -> card.updateCardStatusToTradeAvailable(); + case RESERVED -> card.updateCardStatusToReserved(); + case TRADE_COMPLETE -> card.updateCardStatusToTradeComplete(); + } + } + @Transactional public void deleteCardById( String token,