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 3a1000c1..253bce3c 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 @@ -91,6 +91,23 @@ public ResponseEntity> getMyCardsByStatus( + @RequestHeader(name = "authorization") String token, + @PathVariable CardStatus status, + @RequestParam(required = false) String cursorId, + @RequestParam Integer size + ) { + CardListReadPagingResponseDTO cardListReadPagingResponseDTO = cardService.getMyCardsByStatus( + token, + status, + cursorId, + size + ); + + return ResponseEntity.ok(ResponseFactory.getSingleResult(cardListReadPagingResponseDTO)); + } + @DeleteMapping("/{cardId}") public ResponseEntity deleteCardById( @RequestHeader(name = "authorization") String token, diff --git a/src/main/java/org/prgrms/nabimarketbe/domain/card/repository/CardRepositoryCustom.java b/src/main/java/org/prgrms/nabimarketbe/domain/card/repository/CardRepositoryCustom.java index f12e18f5..3027a050 100644 --- a/src/main/java/org/prgrms/nabimarketbe/domain/card/repository/CardRepositoryCustom.java +++ b/src/main/java/org/prgrms/nabimarketbe/domain/card/repository/CardRepositoryCustom.java @@ -5,6 +5,7 @@ import org.prgrms.nabimarketbe.domain.card.entity.CardStatus; import org.prgrms.nabimarketbe.domain.category.entity.CategoryEnum; import org.prgrms.nabimarketbe.domain.item.entity.PriceRange; +import org.prgrms.nabimarketbe.domain.user.entity.User; import java.util.List; @@ -18,6 +19,13 @@ CardListReadPagingResponseDTO getCardsByCondition( Integer size ); + CardListReadPagingResponseDTO getMyCardsByStatus( + User user, + CardStatus status, + String cursorId, + Integer size + ); + List getSuggestionAvailableCards( Long userId, PriceRange priceRange, diff --git a/src/main/java/org/prgrms/nabimarketbe/domain/card/repository/CardRepositoryImpl.java b/src/main/java/org/prgrms/nabimarketbe/domain/card/repository/CardRepositoryImpl.java index 4f5227f2..da84ae34 100644 --- a/src/main/java/org/prgrms/nabimarketbe/domain/card/repository/CardRepositoryImpl.java +++ b/src/main/java/org/prgrms/nabimarketbe/domain/card/repository/CardRepositoryImpl.java @@ -15,6 +15,7 @@ import org.prgrms.nabimarketbe.domain.category.entity.CategoryEnum; import org.prgrms.nabimarketbe.domain.item.entity.PriceRange; import org.prgrms.nabimarketbe.domain.suggestion.entity.SuggestionType; +import org.prgrms.nabimarketbe.domain.user.entity.User; import java.util.List; @@ -65,6 +66,41 @@ public CardListReadPagingResponseDTO getCardsByCondition( return new CardListReadPagingResponseDTO(cardList, nextCursor); } + @Override + public CardListReadPagingResponseDTO getMyCardsByStatus( + User user, + CardStatus status, + String cursorId, + Integer size + ) { + List cardList = jpaQueryFactory.select( + Projections.fields( + CardListReadResponseDTO.class, + card.cardId, + card.cardTitle, + item.itemName, + item.priceRange, + card.thumbNailImage.as("thumbNail"), + card.status, + card.createdDate.as("createdAt"), + card.modifiedDate.as("modifiedAt") + ) + ) + .from(card) + .leftJoin(item).on(card.item.itemId.eq(item.itemId)) + .where( + cursorId(cursorId), + card.status.eq(status) + ) + .orderBy(card.createdDate.desc()) // 디폴트는 생성일자 최신순 정렬 + .limit(size) + .fetch(); + + String nextCursor = cardList.size() < size ? null : generateCursor(cardList.get(cardList.size() - 1)); + + return new CardListReadPagingResponseDTO(cardList, nextCursor); + } + @Override public List getSuggestionAvailableCards( Long userId, 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 3bebe4dc..a98ffe6f 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 @@ -188,6 +188,24 @@ public CardListResponseDTO getSuggestionAvai return new CardListResponseDTO<>(cardListResponse); } + @Transactional(readOnly = true) + public CardListReadPagingResponseDTO getMyCardsByStatus( + String token, + CardStatus status, + String cursorId, + Integer size + ) { + User user = userRepository.findById(checkService.parseToken(token)) + .orElseThrow(() -> new BaseException(ErrorCode.USER_NOT_FOUND)); + + return cardRepository.getMyCardsByStatus( + user, + status, + cursorId, + size + ); + } + @Transactional public void deleteCardById( String token,