55import com .cmg .comtogether .common .exception .ErrorCode ;
66import com .cmg .comtogether .interest .entity .Interest ;
77import com .cmg .comtogether .product .dto .NaverProductResponseDto ;
8+ import com .cmg .comtogether .product .entity .ProductCategory ;
89import com .cmg .comtogether .user .entity .User ;
910import com .cmg .comtogether .user .entity .UserInterest ;
1011import com .cmg .comtogether .user .repository .UserRepository ;
@@ -21,8 +22,12 @@ public class ProductService {
2122 private final NaverProductService naverProductService ;
2223
2324 public NaverProductResponseDto searchProducts (String category , String query , int display , int start , String sort , String exclude ) {
24- String searchQuery = category + " " + query ;
25- NaverProductResponseDto result = naverProductService .getNaverProducts (searchQuery , display , start , sort , exclude );
25+ ProductCategory productCategory ;
26+ productCategory = ProductCategory .fromDisplayName (category );
27+
28+ String searchQuery = productCategory .getSearchQuery () + " " + query ;
29+
30+ NaverProductResponseDto result = naverProductService .getNaverProducts (searchQuery .trim (), display , start , sort , exclude );
2631 cacheMonitorService .printCacheStats ("naverProducts" );
2732 return result ;
2833 }
@@ -31,12 +36,16 @@ public NaverProductResponseDto recommendProducts(Long userId, String category, S
3136 User user = userRepository .findByIdWithInterests (userId )
3237 .orElseThrow (() -> new BusinessException (ErrorCode .USER_NOT_FOUND ));
3338
39+ ProductCategory productCategory ;
40+ productCategory = ProductCategory .fromDisplayName (category );
41+
3442 String interestString = user .getInterests ().stream ()
3543 .map (UserInterest ::getInterest )
3644 .map (Interest ::getName )
3745 .collect (Collectors .joining (" " ));
38- String searchQuery = category + " " + interestString + query ;
39- NaverProductResponseDto result = naverProductService .getNaverProducts (searchQuery , display , start , sort , exclude );
46+ String searchQuery = productCategory .getSearchQuery () + " " + interestString + " " + query ;
47+
48+ NaverProductResponseDto result = naverProductService .getNaverProducts (searchQuery .trim (), display , start , sort , exclude );
4049 cacheMonitorService .printCacheStats ("naverProducts" );
4150 return result ;
4251 }
0 commit comments