Skip to content

Commit

Permalink
Merge pull request #20 from EWHA-CAPSTONE-COOKSAVE/feature/recipe
Browse files Browse the repository at this point in the history
[차소연] 전체 레시피 조회 시 ingredient의 tag가 null인 경우 처리
  • Loading branch information
Soyeon-Cha authored Apr 17, 2024
2 parents 3cc7e16 + a5585ca commit 6a0dfa8
Showing 1 changed file with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -33,26 +33,38 @@ public class RecipeService {
public List<RecipeResponseDto> getRecipeList(Member member) {
List<RecipeResponseDto> recipeList = new ArrayList<>();

// 전체 recipe 리스트
List<Recipe> recipes = new ArrayList<>();
recipes = recipeRepository.findAll();
int recipeCount = recipes.size();

// 해당 member가 보유한 ingredient 리스트
List<Ingredient> ingredients = new ArrayList<>();
ingredients = ingredientRepository.findAllByMember(member);

// 해당 member가 보유한 ingredient에 대응되는 tag의 tagId 리스트
List<Integer> tags = new ArrayList<>();
for (Ingredient ingredient : ingredients) {
tags.add(ingredient.getTag().getTagId());
// ingredient의 tag
Tag tag = ingredient.getTag();
if(tag != null){
tags.add(tag.getTagId());
}

// 중복되는 tagId 제거
tags = tags.stream().distinct().collect(Collectors.toList());
}
int tagCount = tags.size();

// tags 중 각 recipe에 포함되는 태그의 개수
List<Integer> recipeTagCount = new ArrayList<>();

// recipeTagCount의 값들을 0으로 초기화
for (int i = 0; i < recipeCount; i++) {
recipeTagCount.add(0);
}

// recipeTagCount 값 구하기
for (int i = 0; i < recipeCount; i++) {
for (Integer tagId : tags) {
Tag tag = tagRepository.findById(tagId)
Expand Down

0 comments on commit 6a0dfa8

Please sign in to comment.