Skip to content

Commit

Permalink
comment: add logging
Browse files Browse the repository at this point in the history
  • Loading branch information
nowgnas committed Jan 16, 2024
1 parent c85fa50 commit 75cc3c0
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ public StoreAverageDto getStoreAverageRating() {

@Override
public List<StockChangeDto> getFlowerAmountGroupByStoreId(ProcessOrderDto processOrderDto) {

log.info(processOrderDto.getProducts().get(0).toString());
Map<Long, List<Product>> productsByProductsGroupByStoreId =
productQueryOutPort.findProductsByProductsGroupByStoreId(
new ArrayList<>(processOrderDto.getProducts().keySet()));
Expand Down Expand Up @@ -383,13 +383,27 @@ public ProductList searchByUser(String sentence, Pageable pageable) {
return ProductList.getData(product, products.getTotalElements());
}

@Override
public ProductList searchByUser(Long userId, String sentence, Pageable pageable) {
String prompt = getPrompt(sentence);
String response = chatgptService.sendMessage(prompt);
Page<Product> products =
productQueryOutPort.findProductsByFlowerId(Long.parseLong(response.trim()), pageable);
List<ProductListItem> product = getProduct(products);
List<String> ids = getProductIdsFromProducts(products.getContent());
List<String> data = getProductsIsLiked(userId, ids);
return ProductList.getData(product, data, products.getTotalElements());
}

private String getPrompt(String sentence) {
return "- Please choose one of several flowers. Types include "
+ "\n"
+ "red rose:1, white rose:2, orange rose:3, pink rose:4, blue rose:5, purple rose:6, yellow rose:7, lisianthus:8, hydrangea:9, lavender:10, chrysanthemum:11, sunflower:12, carnation:13, gerbera:14, freesia:15, tulip:16, ranunculus:17, gypsophila:18, statis:19, daisy:20, peony:21, delphinium:22 \n"
+ "- The format is flowername:flowerid and only one flowerId is responded\n"
+ "- Just choose the flower whose language is most related to this sentence\n"
+ "\""
+ sentence
+ "\""
+ "\n"
+ "respond just flowerId exclude flowerName";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,6 @@ ProductsForAdmin getProductsForAdmin(
ProductCommand.AdminSelectOption adminSelectOption, Pageable pageable);

ProductList searchByUser(String sentence, Pageable pageable);

ProductList searchByUser(Long userId, String sentence, Pageable pageable);
}
Original file line number Diff line number Diff line change
Expand Up @@ -371,13 +371,17 @@ public void deleteProductsByAdmin(@RequestBody List<String> productIds) {

@PostMapping("search")
public CommonResponse<ProductList> searchProducts(
@RequestHeader Optional<Long> userId,
@RequestBody String sentence,
@PageableDefault(
page = 0,
size = 10,
sort = {"createdAt"},
direction = Sort.Direction.DESC)
Pageable pageable) {
return CommonResponse.success(productQueryUseCase.searchByUser(sentence, pageable));
if (userId.isPresent())
return CommonResponse.success(
productQueryUseCase.searchByUser(userId.get(), sentence, pageable));
else return CommonResponse.success(productQueryUseCase.searchByUser(sentence, pageable));
}
}
}

0 comments on commit 75cc3c0

Please sign in to comment.