Skip to content

Commit

Permalink
Revert "Fix: 상품 필터링 로직 수정"
Browse files Browse the repository at this point in the history
  • Loading branch information
namsh1125 authored Feb 5, 2024
1 parent f91a7a7 commit fec7b42
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 127 deletions.
1 change: 0 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
21 changes: 0 additions & 21 deletions src/main/java/kea/dpang/item/config/RedisConfig.java

This file was deleted.

73 changes: 17 additions & 56 deletions src/main/java/kea/dpang/item/controller/ItemController.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

import java.util.List;


@RestController
@RequiredArgsConstructor
@Tag(name = "item API", description = "상품 관련 API 입니다.")
Expand Down Expand Up @@ -78,13 +77,13 @@ public ResponseEntity<SuccessResponse<List<ItemDto>>> getItemList(
);
}

@GetMapping("/{itemId}")
@Operation(summary = "상품 정보 조회", description = "상품 ID를 통해 상품 정보를 조회합니다.")
public ResponseEntity<SuccessResponse<ItemDto>> getItemInfo(
@PathVariable @Parameter(description = "상품ID", example = "1") Long itemId
) {
ItemDto item = itemService.getItemInfo(itemId);

@GetMapping("/{itemId}/detail")
@Operation(summary = "상품 상세 정보 조회", description = "상품 ID를 통해 상세한 상품 정보를 조회합니다.")
public ResponseEntity<SuccessResponse<ItemResponseDto>> 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
Expand All @@ -104,7 +103,6 @@ public ResponseEntity<SuccessResponse<ItemDetailDto>> getItemDetailInfo(
);
}


@GetMapping("/{itemId}/reviews")
@Operation(summary = "상품별 리뷰 리스트 조회", description = "상품별로 리뷰 리스트를 페이지 정보에 따라 조회합니다.")
public ResponseEntity<SuccessResponse<List<ReviewDto>>> getReviewList(
Expand All @@ -119,35 +117,20 @@ public ResponseEntity<SuccessResponse<List<ReviewDto>>> getReviewList(
);
}


@GetMapping("/popular/list")
@Operation(summary = "인기 상품 리스트 조회", description = "인기 상품 정보를 페이지 정보에 따라 조회합니다.")
public ResponseEntity<SuccessResponse<List<PopularItemDto>>> getPopularItems(@RequestParam List<Long> itemIdList, Pageable pageable) {
List<PopularItemDto> popularItems = itemService.getPopularItems();
return new ResponseEntity<>(
new SuccessResponse<>(HttpStatus.OK.value(),"인기 상품 리스트가 조회되었습니다.", popularItems),
HttpStatus.OK
);
@Operation(summary = "인기 상품 리스트 조회", description = "지정된 상품 ID 리스트에 대한 인기 상품 정보를 페이지 정보에 따라 조회합니다.")
public ResponseEntity<SuccessResponse<List<ItemDetailDto>>> getPopularItems(Pageable pageable) {
// Todo: 인기 상품 리스트 조회 API 구현 필요
// List<PopularItemDto> 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<SuccessResponse<Page<ItemCardDto>>> 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<ItemCardDto> 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<BaseResponse> updateItem(
@PathVariable @Parameter(description = "상품ID", example = "1") Long itemId, @RequestBody UpdateItemRequestDto dto
Expand Down Expand Up @@ -186,27 +169,5 @@ public ResponseEntity<BaseResponse> changeStock(
);
}

// 주문(Order)
@GetMapping("/{itemId}")
@Operation(summary = "(BE) 상품 정보 조회", description = "상품 정보를 조회합니다.")
public ResponseEntity<SuccessResponse<ItemInquiryDto>> 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<SuccessResponse<List<ItemSimpleListDto>>> getCartInquiryItem(@RequestParam List<Long> itemIds) {
List<ItemSimpleListDto> data = itemService.getCartItemsInquiry(itemIds);
return new ResponseEntity<>(
new SuccessResponse<>(HttpStatus.OK.value(), "상품 목록 전달 성공", data),
HttpStatus.OK
);
}

}
8 changes: 3 additions & 5 deletions src/main/java/kea/dpang/item/repository/ItemRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,13 @@ public interface ItemRepository extends JpaRepository<Item, Long> {
@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<Item> 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,
Expand Down
19 changes: 0 additions & 19 deletions src/main/java/kea/dpang/item/service/ItemService.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ Page<ItemDetailDto> getItemList(
Pageable pageable
);


Page<ItemCardDto> filterItems(Category category, SubCategory subCategory, Long sellerId, Double minPrice, Double maxPrice, String keyword, Pageable pageable);
// Todo: 인기 상품 리스트 조회

/**
Expand All @@ -58,23 +56,6 @@ Page<ItemDetailDto> getItemList(
*/
void deleteItem(List<Long> itemIds);

/**
* 인기 상품을 조회합니다.
*
* @return 조회된 인기 상품 목록이 담긴 DTO 리스트
*/
List<PopularItemDto> getPopularItems();

void incrementViewCount(Long itemId);

/**
* 주어진 ID에 해당하는 상품의 재고 수량을 조회합니다.
*
* @param itemId 재고 수량을 조회할 상품의 ID
* @return 조회된 재고 수량
*/
int getStockQuantity(Long itemId);

/**
* 주어진 ID에 해당하는 상품의 재고 수량을 업데이트 합니다.
*
Expand Down
31 changes: 6 additions & 25 deletions src/main/java/kea/dpang/item/service/ItemServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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<String, String> redisTemplate;
private static final String ITEM_VIEW_COUNT_KEY = "item:viewCount";
private final StringRedisTemplate redisTemplate;

// 상품 등록
@Override
Expand Down Expand Up @@ -70,25 +69,6 @@ public ItemDto getItemInfo(Long itemId) {
// 상품 상세 정보 조회
@Override
@Transactional(readOnly = true)
public List<PopularItemDto> getPopularItems() {
// Redis에서 조회수를 기반으로 인기 상품 ID와 점수를 가져옴
Set<ZSetOperations.TypedTuple<String>> 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);

Expand All @@ -107,14 +87,15 @@ public ItemDetailDto getItemDetailInfo(Long itemId) {
}

@Override
public Page<ItemDetailDto> 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<ItemDetailDto> 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<Item> 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));
}


Expand Down

0 comments on commit fec7b42

Please sign in to comment.