From 7ade887c2b9d1f2f25b06861c2060fb479b110c4 Mon Sep 17 00:00:00 2001 From: hi-june Date: Fri, 10 Nov 2023 17:19:33 +0900 Subject: [PATCH 1/2] =?UTF-8?q?NABI-186--feat=20:=20=EC=82=AC=EC=9A=A9?= =?UTF-8?q?=EC=9E=90=EC=9D=98=20=EC=B9=B4=EB=93=9C=20=EC=A1=B0=ED=9A=8C=20?= =?UTF-8?q?api=20-=20query=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../card/repository/CardRepositoryCustom.java | 8 +++++ .../card/repository/CardRepositoryImpl.java | 36 +++++++++++++++++++ 2 files changed, 44 insertions(+) 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, From 7b798c5e1b866d7f01248af301cccd309c04d43d Mon Sep 17 00:00:00 2001 From: hi-june Date: Fri, 10 Nov 2023 17:20:23 +0900 Subject: [PATCH 2/2] =?UTF-8?q?NABI-186--feat=20:=20=EC=82=AC=EC=9A=A9?= =?UTF-8?q?=EC=9E=90=EC=9D=98=20=EC=B9=B4=EB=93=9C=20=EC=A1=B0=ED=9A=8C=20?= =?UTF-8?q?api=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/card/api/CardController.java | 17 +++++++++++++++++ .../domain/card/service/CardService.java | 18 ++++++++++++++++++ 2 files changed, 35 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 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/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,