diff --git a/build.gradle b/build.gradle index 0062882..37df237 100644 --- a/build.gradle +++ b/build.gradle @@ -23,7 +23,6 @@ dependencies { // Spring implementation 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-client' implementation 'org.springframework.cloud:spring-cloud-starter-openfeign' - implementation 'org.springframework.boot:spring-boot-starter-data-redis' implementation 'org.springframework.boot:spring-boot-starter-data-jpa' implementation 'org.springframework.boot:spring-boot-starter-web' developmentOnly 'org.springframework.boot:spring-boot-devtools' diff --git a/src/main/java/kea/dpang/item/config/RedisConfig.java b/src/main/java/kea/dpang/item/config/RedisConfig.java deleted file mode 100644 index 8cdf54c..0000000 --- a/src/main/java/kea/dpang/item/config/RedisConfig.java +++ /dev/null @@ -1,21 +0,0 @@ -package kea.dpang.item.config; - -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.data.redis.connection.RedisConnectionFactory; -import org.springframework.data.redis.core.RedisTemplate; -import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer; -import org.springframework.data.redis.serializer.StringRedisSerializer; - -@Configuration -public class RedisConfig { - - @Bean - public RedisTemplate redisTemplate(RedisConnectionFactory redisConnectionFactory) { - RedisTemplate redisTemplate = new RedisTemplate<>(); - redisTemplate.setConnectionFactory(redisConnectionFactory); - redisTemplate.setKeySerializer(new StringRedisSerializer()); - redisTemplate.setValueSerializer(new GenericJackson2JsonRedisSerializer()); - return redisTemplate; - } -} diff --git a/src/main/java/kea/dpang/item/controller/ItemController.java b/src/main/java/kea/dpang/item/controller/ItemController.java index c279d55..73b7d4c 100644 --- a/src/main/java/kea/dpang/item/controller/ItemController.java +++ b/src/main/java/kea/dpang/item/controller/ItemController.java @@ -21,7 +21,6 @@ import java.util.List; - @RestController @RequiredArgsConstructor @Tag(name = "item API", description = "상품 관련 API 입니다.") @@ -78,13 +77,13 @@ public ResponseEntity>> getItemList( ); } + @GetMapping("/{itemId}") + @Operation(summary = "상품 정보 조회", description = "상품 ID를 통해 상품 정보를 조회합니다.") + public ResponseEntity> getItemInfo( + @PathVariable @Parameter(description = "상품ID", example = "1") Long itemId + ) { + ItemDto item = itemService.getItemInfo(itemId); - @GetMapping("/{itemId}/detail") - @Operation(summary = "상품 상세 정보 조회", description = "상품 ID를 통해 상세한 상품 정보를 조회합니다.") - public ResponseEntity> getItem(@PathVariable @Parameter(description = "상품ID", example = "1") Long itemId) { - ItemResponseDto item = itemService.getItem(itemId); - itemService.incrementViewCount(itemId); - log.info("상품 상세 정보 조회 완료. 상품 ID: {}", item.getItemId()); return new ResponseEntity<>( new SuccessResponse<>(HttpStatus.OK.value(), "상품 정보가 조회되었습니다.", item), HttpStatus.OK @@ -104,7 +103,6 @@ public ResponseEntity> getItemDetailInfo( ); } - @GetMapping("/{itemId}/reviews") @Operation(summary = "상품별 리뷰 리스트 조회", description = "상품별로 리뷰 리스트를 페이지 정보에 따라 조회합니다.") public ResponseEntity>> getReviewList( @@ -119,35 +117,20 @@ public ResponseEntity>> getReviewList( ); } - @GetMapping("/popular/list") - @Operation(summary = "인기 상품 리스트 조회", description = "인기 상품 정보를 페이지 정보에 따라 조회합니다.") - public ResponseEntity>> getPopularItems(@RequestParam List itemIdList, Pageable pageable) { - List popularItems = itemService.getPopularItems(); - return new ResponseEntity<>( - new SuccessResponse<>(HttpStatus.OK.value(),"인기 상품 리스트가 조회되었습니다.", popularItems), - HttpStatus.OK - ); + @Operation(summary = "인기 상품 리스트 조회", description = "지정된 상품 ID 리스트에 대한 인기 상품 정보를 페이지 정보에 따라 조회합니다.") + public ResponseEntity>> getPopularItems(Pageable pageable) { + // Todo: 인기 상품 리스트 조회 API 구현 필요 +// List popularItems = itemService.getPopularItems(); +// log.info("인기 상품 목록 조회 완료. 조회된 인기 상품 수: {}", popularItems.size()); +// return new ResponseEntity<>( +// new SuccessResponse<>(HttpStatus.OK.value(), "인기 상품 리스트가 조회되었습니다.", popularItems), +// HttpStatus.OK +// ); + return null; } - @GetMapping("/filter") - @Operation(summary = "상품 필터링 조회", description = "주어진 필터 조건에 따라 상품을 조회합니다.") - public ResponseEntity>> filterItems( - @RequestParam(defaultValue = "전체") Category category, - @RequestParam(defaultValue = "전체") SubCategory subCategory, - @RequestParam(required = false) Long sellerId, - @RequestParam(defaultValue = "0") Double minPrice, - @RequestParam(defaultValue = "10000000") Double maxPrice, - @RequestParam(defaultValue = "") String keyword, - Pageable pageable) { - Page items = itemService.filterItems(category, subCategory, sellerId, minPrice, maxPrice, keyword, pageable); - return new ResponseEntity<>( - new SuccessResponse<>(HttpStatus.OK.value(), "상품 필터링이 완료되었습니다.", items), - HttpStatus.OK - ); - } - - @PutMapping + @PutMapping("/{itemId}") @Operation(summary = "상품 수정", description = "상품 ID에 해당하는 상품 정보를 수정합니다.") public ResponseEntity updateItem( @PathVariable @Parameter(description = "상품ID", example = "1") Long itemId, @RequestBody UpdateItemRequestDto dto @@ -186,27 +169,5 @@ public ResponseEntity changeStock( ); } - // 주문(Order) - @GetMapping("/{itemId}") - @Operation(summary = "(BE) 상품 정보 조회", description = "상품 정보를 조회합니다.") - public ResponseEntity> getInquiryItem(@RequestParam Long itemId) { - Item item = itemService.getItemInquiry(itemId); - ItemInquiryDto itemInquiryDto = new ItemInquiryDto(item); - return new ResponseEntity<>( - new SuccessResponse<>(HttpStatus.OK.value(), "상품명이 조회되었습니다.", itemInquiryDto), - HttpStatus.OK - ); - } - - // 유저(User) - 장바구니 및 위시리스트에 전달할 상품 정보 리스트 - @GetMapping("/cart/inquiryItem") - @Operation(summary = "(BE) 상품 요약 정보 조회", description = "상품의 일부 정보를 조회합니다.") - public ResponseEntity>> getCartInquiryItem(@RequestParam List itemIds) { - List data = itemService.getCartItemsInquiry(itemIds); - return new ResponseEntity<>( - new SuccessResponse<>(HttpStatus.OK.value(), "상품 목록 전달 성공", data), - HttpStatus.OK - ); - } } \ No newline at end of file diff --git a/src/main/java/kea/dpang/item/repository/ItemRepository.java b/src/main/java/kea/dpang/item/repository/ItemRepository.java index 6c0ea7e..4766528 100644 --- a/src/main/java/kea/dpang/item/repository/ItemRepository.java +++ b/src/main/java/kea/dpang/item/repository/ItemRepository.java @@ -14,15 +14,13 @@ public interface ItemRepository extends JpaRepository { @Query("SELECT i FROM Item i WHERE " + "(:category IS NULL OR i.category = :category) AND " + "(:subCategory IS NULL OR i.subCategory = :subCategory) AND " + - "(:sellerId IS NULL OR i.sellerId = :sellerId) AND " + - "(:minPrice = 0 OR i.itemPrice >= :minPrice) AND " + - "(:maxPrice = 2000000 OR i.itemPrice <= :maxPrice) AND " + - "(i.itemName LIKE %:keyword%)") + "(:minPrice = 0 OR i.price >= :minPrice) AND " + + "(:maxPrice = 2000000 OR i.price <= :maxPrice) AND " + + "(i.name LIKE %:keyword%)") // "(i.itemName LIKE %:keyword% OR i.description LIKE %:keyword%)") Page filterItems( @Param("category") Category category, @Param("subCategory") SubCategory subCategory, - @Param("sellerId") Long sellerId, @Param("minPrice") Double minPrice, @Param("maxPrice") Double maxPrice, @Param("keyword") String keyword, diff --git a/src/main/java/kea/dpang/item/service/ItemService.java b/src/main/java/kea/dpang/item/service/ItemService.java index e2cbbcd..50ab679 100644 --- a/src/main/java/kea/dpang/item/service/ItemService.java +++ b/src/main/java/kea/dpang/item/service/ItemService.java @@ -39,8 +39,6 @@ Page getItemList( Pageable pageable ); - - Page filterItems(Category category, SubCategory subCategory, Long sellerId, Double minPrice, Double maxPrice, String keyword, Pageable pageable); // Todo: 인기 상품 리스트 조회 /** @@ -58,23 +56,6 @@ Page getItemList( */ void deleteItem(List itemIds); - /** - * 인기 상품을 조회합니다. - * - * @return 조회된 인기 상품 목록이 담긴 DTO 리스트 - */ - List getPopularItems(); - - void incrementViewCount(Long itemId); - - /** - * 주어진 ID에 해당하는 상품의 재고 수량을 조회합니다. - * - * @param itemId 재고 수량을 조회할 상품의 ID - * @return 조회된 재고 수량 - */ - int getStockQuantity(Long itemId); - /** * 주어진 ID에 해당하는 상품의 재고 수량을 업데이트 합니다. * diff --git a/src/main/java/kea/dpang/item/service/ItemServiceImpl.java b/src/main/java/kea/dpang/item/service/ItemServiceImpl.java index aba6603..a600a05 100644 --- a/src/main/java/kea/dpang/item/service/ItemServiceImpl.java +++ b/src/main/java/kea/dpang/item/service/ItemServiceImpl.java @@ -11,8 +11,7 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; -import org.springframework.data.redis.core.RedisTemplate; -import org.springframework.data.redis.core.ZSetOperations; +import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -25,8 +24,8 @@ public class ItemServiceImpl implements ItemService { private final ItemRepository itemRepository; private final SellerServiceFeignClient sellerServiceFeignClient; - private static final String ITEM_VIEW_COUNT_KEY = "item:viewcount"; - private final RedisTemplate redisTemplate; + private static final String ITEM_VIEW_COUNT_KEY = "item:viewCount"; + private final StringRedisTemplate redisTemplate; // 상품 등록 @Override @@ -70,25 +69,6 @@ public ItemDto getItemInfo(Long itemId) { // 상품 상세 정보 조회 @Override @Transactional(readOnly = true) - public List getPopularItems() { - // Redis에서 조회수를 기반으로 인기 상품 ID와 점수를 가져옴 - Set> items = redisTemplate.opsForZSet() - .reverseRangeWithScores(ITEM_VIEW_COUNT_KEY, 0, -1); - - // 가져온 데이터를 PopularItemDto 리스트로 변환 - return items.stream().map(item -> { - Long itemId = Long.valueOf(item.getValue()); - Double score = item.getScore(); - String itemName = "Item " + itemId; - - return new PopularItemDto(itemId, itemName, score); - }).collect(Collectors.toList()); - } - - @Override - public void incrementViewCount(Long itemId) { - redisTemplate.opsForZSet().incrementScore(ITEM_VIEW_COUNT_KEY, String.valueOf(itemId), 1); - public ItemDetailDto getItemDetailInfo(Long itemId) { log.info("item ID로부터 아이템 조회를 시작합니다 : {}", itemId); @@ -107,14 +87,15 @@ public ItemDetailDto getItemDetailInfo(Long itemId) { } @Override - public Page getItemList(Category category, SubCategory subCategory, Long sellerId, Double minPrice, Double maxPrice, String keyword, Pageable pageable) { - log.info("상품 리스트 조회를 시작합니다 : 카테고리 = {}, 서브카테고리 = {}, 판매자ID = {}, 최소가격 = {}, 최대가격 = {}, 키워드 = {}, 페이지 요청 정보 = {}", category, subCategory, sellerId, minPrice, maxPrice, keyword, pageable); + public Page getItemList(Category category, SubCategory subCategory, Double minPrice, Double maxPrice, String keyword, Long sellerId, Pageable pageable) { + log.info("상품 리스트 조회를 시작합니다 : 카테고리 = {}, 서브카테고리 = {}, 최소가격 = {}, 최대가격 = {}, 키워드 = {}, 판매자ID = {}, 페이지 요청 정보 = {}", category, subCategory, minPrice, maxPrice, keyword, sellerId, pageable); Page items = itemRepository.filterItems(category, subCategory, minPrice, maxPrice, keyword, pageable); log.info("판매자 이름 조회를 시작합니다 : 판매자ID = {}", sellerId); String sellerName = sellerServiceFeignClient.getSeller(sellerId).getBody().getData().toLowerCase(); log.info("상품 리스트를 ItemResponseDto로 변환합니다."); + return items.map(item -> new ItemDetailDto(item, sellerName)); }