From 0279c240245490f90a37e8ded44962f9f04d9753 Mon Sep 17 00:00:00 2001 From: Due <48638700+Due-IT@users.noreply.github.com> Date: Mon, 18 Nov 2024 23:38:17 +0900 Subject: [PATCH] =?UTF-8?q?[Server]=20fix=20:=20=EC=A0=84=EC=B2=B4=20?= =?UTF-8?q?=EC=B9=B4=ED=85=8C=EA=B3=A0=EB=A6=AC=EC=97=90=EC=84=9C=20?= =?UTF-8?q?=EB=A0=88=EC=8B=9C=ED=94=BC=EB=A5=BC=20=EC=B6=94=EC=B2=9C=20?= =?UTF-8?q?=EB=B0=9B=EB=8A=94=EB=8B=A4=20(#66)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fix(AiRecipeRecommendClient) : 전체 카테고리에서 레시피를 추천 받는다 - 재료 추가/삭제시, 전체 카테고리 기준으로 레시피를 추천 받습니다. - 카테고리를 특정하여 레시피를 추천받는 ai측 api와 카테고리를 지정하지 않고 레시피를 추천 받는 api가 다름에 따라, 메서드를 분리하였습니다. --- .../application/AiRecipeRecommendClient.java | 28 ++++++++++++++++--- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/Server/banchango/src/main/java/com/sundaegukbap/banchango/ai/application/AiRecipeRecommendClient.java b/Server/banchango/src/main/java/com/sundaegukbap/banchango/ai/application/AiRecipeRecommendClient.java index 0acdccb..9e8bc41 100644 --- a/Server/banchango/src/main/java/com/sundaegukbap/banchango/ai/application/AiRecipeRecommendClient.java +++ b/Server/banchango/src/main/java/com/sundaegukbap/banchango/ai/application/AiRecipeRecommendClient.java @@ -5,14 +5,14 @@ import com.sundaegukbap.banchango.ingredient.domain.Ingredient; import com.sundaegukbap.banchango.recipe.domain.RecipeCategory; import jakarta.transaction.Transactional; +import java.util.List; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; import org.springframework.web.client.RestTemplate; -import java.util.List; - @Component public class AiRecipeRecommendClient { + @Value("${api.aiBaseUrl}") private String aiBaseUrl; private final RestTemplate restTemplate; @@ -22,10 +22,30 @@ public AiRecipeRecommendClient(RestTemplate restTemplate) { } @Transactional - public List getRecommendedRecipesFromAI(RecipeCategory category, List ingredientList) { + public List getRecommendedRecipesFromAI(RecipeCategory category, + List ingredientList) { AiRecipeRecommendRequest request = AiRecipeRecommendRequest.of(category, ingredientList); - AiRecipeRecommendResponse response = restTemplate.postForObject(aiBaseUrl + "/category_recommend", request, AiRecipeRecommendResponse.class); + + AiRecipeRecommendResponse response; + if (category == RecipeCategory.전체) { + response = getRecipesOfAllCategories(request); + } else { + response = getRecipesOfSpecificCategories(request); + } return response.recommended_recipes(); } + + private AiRecipeRecommendResponse getRecipesOfSpecificCategories( + AiRecipeRecommendRequest request) { + AiRecipeRecommendResponse response = restTemplate.postForObject( + aiBaseUrl + "/category_recommend", request, AiRecipeRecommendResponse.class); + return response; + } + + private AiRecipeRecommendResponse getRecipesOfAllCategories(AiRecipeRecommendRequest request) { + AiRecipeRecommendResponse response = restTemplate.postForObject( + aiBaseUrl + "/recommend", request, AiRecipeRecommendResponse.class); + return response; + } }