Skip to content

Commit

Permalink
♻️ remove unnecessary method
Browse files Browse the repository at this point in the history
  • Loading branch information
hyxrxn committed Sep 22, 2024
1 parent 6d51f41 commit 95153d0
Showing 1 changed file with 10 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,21 @@ public List<RecipeHomeWithMineResponse> readRecipes(UserInfo userInfo, PageRecip
);

List<RecipeHomeResponse> recipeHomeResponses = recipeRepository.findRecipeData(recipeIds);
return convertToRecipeHomeResponses(userInfo, recipeHomeResponses);

return recipeHomeResponses.stream()
.map(recipeHomeResponse -> new RecipeHomeWithMineResponse(userInfo, recipeHomeResponse))
.sorted(Comparator.comparing(RecipeHomeWithMineResponse::recipeId).reversed())
.toList();
}

public List<RecipeHomeWithMineResponse> readLikeRecipes(UserInfo userInfo) {
List<Long> likeRecipeIds = likeRepository.findRecipeIdsByUserId(userInfo.getId());
List<RecipeHomeResponse> recipeHomeResponses = recipeRepository.findRecipeData(likeRecipeIds);
return convertToRecipeHomeResponses(userInfo, recipeHomeResponses);

return recipeHomeResponses.stream()
.map(recipeHomeResponse -> new RecipeHomeWithMineResponse(userInfo, recipeHomeResponse))
.sorted(Comparator.comparing(RecipeHomeWithMineResponse::recipeId).reversed())
.toList();
}

public RecipeResponse createRecipe(UserInfo userInfo, RecipeRequest recipeRequest) {
Expand Down Expand Up @@ -116,29 +124,6 @@ public void deleteRecipe(UserInfo userInfo, long recipeId) {
});
}

private List<RecipeHomeWithMineResponse> convertToRecipeHomeResponses(
UserInfo userInfo,
List<RecipeHomeResponse> recipeHomeResponses
) {
Collection<List<RecipeHomeResponse>> groupedRecipeData = recipeHomeResponses.stream()
.collect(Collectors.groupingBy(RecipeHomeResponse::recipeId))
.values();

return groupedRecipeData.stream()
.map(data -> getMainRecipeResponse(userInfo, data))
.sorted(Comparator.comparing(RecipeHomeWithMineResponse::recipeId).reversed())
.collect(Collectors.toList());
}

private RecipeHomeWithMineResponse getMainRecipeResponse(UserInfo userInfo, List<RecipeHomeResponse> groupedResponses) {
RecipeHomeResponse firstResponse = groupedResponses.getFirst();

return new RecipeHomeWithMineResponse(
userInfo,
firstResponse
);
}

private List<IngredientResponse> getIngredientResponses(List<RecipeDataResponse> groupedResponses) {
return groupedResponses.stream()
.map(r -> new IngredientResponse(r.ingredientId(), r.ingredientName(), r.ingredientRequirement()))
Expand Down

0 comments on commit 95153d0

Please sign in to comment.