Skip to content

Commit

Permalink
[Server] fix : 전체 카테고리에서 레시피를 추천 받는다 (#66)
Browse files Browse the repository at this point in the history
fix(AiRecipeRecommendClient) : 전체 카테고리에서 레시피를 추천 받는다

- 재료 추가/삭제시, 전체 카테고리 기준으로 레시피를 추천 받습니다.
- 카테고리를 특정하여 레시피를 추천받는 ai측 api와 카테고리를 지정하지 않고 레시피를 추천 받는 api가 다름에 따라, 메서드를 분리하였습니다.
  • Loading branch information
Due-IT authored Nov 18, 2024
1 parent c16b6d4 commit 0279c24
Showing 1 changed file with 24 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -22,10 +22,30 @@ public AiRecipeRecommendClient(RestTemplate restTemplate) {
}

@Transactional
public List<Long> getRecommendedRecipesFromAI(RecipeCategory category, List<Ingredient> ingredientList) {
public List<Long> getRecommendedRecipesFromAI(RecipeCategory category,
List<Ingredient> 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;
}
}

0 comments on commit 0279c24

Please sign in to comment.