Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Server] fix : 전체 카테고리에서 레시피를 추천 받는다 #66

Merged
merged 1 commit into from
Nov 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
}
Loading