Skip to content

Commit

Permalink
fix : 이 부분에서 정렬되는 건가?
Browse files Browse the repository at this point in the history
  • Loading branch information
Due-IT committed Oct 2, 2024
1 parent 635800a commit bfd7325
Showing 1 changed file with 13 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.Optional;
import java.util.stream.Collectors;

@Service
Expand Down Expand Up @@ -55,14 +57,17 @@ public void refreshRecommendedRecipes(Long userId, RecipeCategory recipeCategory
User user = userRepository.findById(userId)
.orElseThrow(() -> new NoSuchElementException("no user"));
List<Long> recommendedRecipeIds = aiRecipeRecommendClient.getRecommendedRecipesFromAI(recipeCategory, ingredients);
List<Recipe> recipes = recipeRepository.findAllById(recommendedRecipeIds);

recipes.forEach(recipe -> {
UserRecommendedRecipe recommendedRecipe = UserRecommendedRecipe.builder()
.user(user)
.recipe(recipe)
.build();
recommendedRecipeRepository.save(recommendedRecipe);
List<Recipe> recipes = new ArrayList<>();
recommendedRecipeIds.forEach(recommendedRecipeId -> {
Optional<Recipe> recipe = recipeRepository.findById(recommendedRecipeId);
if(recipe.isPresent()) recipes.add(recipe.get());
});
List<UserRecommendedRecipe> recommendedRecipes = recipes.stream()
.map(recipe -> UserRecommendedRecipe.builder()
.user(user)
.recipe(recipe)
.build())
.collect(Collectors.toList());
recommendedRecipeRepository.saveAll(recommendedRecipes);
}
}

0 comments on commit bfd7325

Please sign in to comment.