Skip to content

Commit

Permalink
Feat: Add New Item List
Browse files Browse the repository at this point in the history
  • Loading branch information
oo-ni committed Feb 7, 2024
1 parent d74e1d4 commit 7edd2ab
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 3 deletions.
10 changes: 10 additions & 0 deletions src/main/java/kea/dpang/item/controller/ItemController.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,16 @@ public ResponseEntity<SuccessResponse<List<ItemDetailDto>>> getPopularItems(Page
);
}

@GetMapping("/new/list")
@Operation(summary = "신제품 리스트 조회", description = "최신 상품 정보를 페이지 정보에 따라 조회합니다.")
public ResponseEntity<SuccessResponse<List<ItemDto>>> getNewItems(Pageable pageable) {
List<ItemDto> newItems = itemService.getNewItems(pageable);
return new ResponseEntity<>(
new SuccessResponse<>(HttpStatus.OK.value(),"신제품 리스트가 조회되었습니다.", newItems),
HttpStatus.OK
);
}

@PutMapping("/{itemId}")
@Operation(summary = "상품 수정", description = "상품 ID에 해당하는 상품 정보를 수정합니다.")
public ResponseEntity<BaseResponse> updateItem(
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/kea/dpang/item/repository/ItemRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@

public interface ItemRepository extends JpaRepository<Item, Long>, JpaSpecificationExecutor<Item> {

List<Item> findAllBySellerId (Long sellerId);
List<Item> findAllBySellerId(Long sellerId);

List<Item> findAllByEventId (Long eventId);
List<Item> findAllByEventId(Long eventId);

List<Item> findByOrderByCreatedTime(Pageable pageable);

}

5 changes: 5 additions & 0 deletions src/main/java/kea/dpang/item/service/ItemService.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ Page<ItemDetailDto> getItemList(
*/
List<ItemDetailDto> getPopularItems(Pageable pageable);

/**
* 신상품을 조회합니다.
*/
List<ItemDto> getNewItems(Pageable pageable);

void incrementViewCount(Long itemId);

/**
Expand Down
12 changes: 11 additions & 1 deletion src/main/java/kea/dpang/item/service/ItemServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,22 @@ public List<ItemDetailDto> 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<ItemDto> getNewItems(Pageable pageable) {
log.info("신제품 리스트 조회를 시작합니다.");
return itemRepository.findByOrderByCreatedTime(pageable)
.stream()
.map(ItemDto::new)
.toList();
}

// 상품 상세 정보 조회
@Override
@Transactional(readOnly = true)
Expand Down

0 comments on commit 7edd2ab

Please sign in to comment.