diff --git a/src/main/java/kea/dpang/item/controller/ItemController.java b/src/main/java/kea/dpang/item/controller/ItemController.java index aa973ec..bdd66eb 100644 --- a/src/main/java/kea/dpang/item/controller/ItemController.java +++ b/src/main/java/kea/dpang/item/controller/ItemController.java @@ -129,6 +129,16 @@ public ResponseEntity>> getPopularItems(Page ); } + @GetMapping("/new/list") + @Operation(summary = "신제품 리스트 조회", description = "최신 상품 정보를 페이지 정보에 따라 조회합니다.") + public ResponseEntity>> getNewItems(Pageable pageable) { + List newItems = itemService.getNewItems(pageable); + return new ResponseEntity<>( + new SuccessResponse<>(HttpStatus.OK.value(),"신제품 리스트가 조회되었습니다.", newItems), + HttpStatus.OK + ); + } + @PutMapping("/{itemId}") @Operation(summary = "상품 수정", description = "상품 ID에 해당하는 상품 정보를 수정합니다.") public ResponseEntity updateItem( diff --git a/src/main/java/kea/dpang/item/repository/ItemRepository.java b/src/main/java/kea/dpang/item/repository/ItemRepository.java index 24d9c3c..0225c7e 100644 --- a/src/main/java/kea/dpang/item/repository/ItemRepository.java +++ b/src/main/java/kea/dpang/item/repository/ItemRepository.java @@ -15,9 +15,11 @@ public interface ItemRepository extends JpaRepository, JpaSpecificationExecutor { - List findAllBySellerId (Long sellerId); + List findAllBySellerId(Long sellerId); - List findAllByEventId (Long eventId); + List findAllByEventId(Long eventId); + + List findByOrderByCreatedTime(Pageable pageable); } diff --git a/src/main/java/kea/dpang/item/service/ItemService.java b/src/main/java/kea/dpang/item/service/ItemService.java index 5bb5889..7b1b488 100644 --- a/src/main/java/kea/dpang/item/service/ItemService.java +++ b/src/main/java/kea/dpang/item/service/ItemService.java @@ -46,6 +46,11 @@ Page getItemList( */ List getPopularItems(Pageable pageable); + /** + * 신상품을 조회합니다. + */ + List getNewItems(Pageable pageable); + void incrementViewCount(Long itemId); /** diff --git a/src/main/java/kea/dpang/item/service/ItemServiceImpl.java b/src/main/java/kea/dpang/item/service/ItemServiceImpl.java index 83e4642..166c6cb 100644 --- a/src/main/java/kea/dpang/item/service/ItemServiceImpl.java +++ b/src/main/java/kea/dpang/item/service/ItemServiceImpl.java @@ -114,12 +114,22 @@ public List getPopularItems(Pageable pageable) { return popularItems; } - + // 조회수 증가 (인기 상품 조회용) @Override public void incrementViewCount(Long itemId) { redisTemplate.opsForZSet().incrementScore(ITEM_VIEW_COUNT_KEY, String.valueOf(itemId), 1); } + // 신상품 조회 + @Override + public List getNewItems(Pageable pageable) { + log.info("신제품 리스트 조회를 시작합니다."); + return itemRepository.findByOrderByCreatedTime(pageable) + .stream() + .map(ItemDto::new) + .toList(); + } + // 상품 상세 정보 조회 @Override @Transactional(readOnly = true)