From ac96beb7fa91c9df7e868b9ce740324a119a5004 Mon Sep 17 00:00:00 2001 From: Soyeon-Cha <7103sy@naver.com> Date: Wed, 17 Apr 2024 19:58:50 +0900 Subject: [PATCH 1/2] =?UTF-8?q?style:=20=EB=A0=88=EC=8B=9C=ED=94=BC=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=20=EA=B4=80=EB=A0=A8=20=EC=A3=BC=EC=84=9D=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CookSave/CookSaveback/Recipe/service/RecipeService.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/java/CookSave/CookSaveback/Recipe/service/RecipeService.java b/src/main/java/CookSave/CookSaveback/Recipe/service/RecipeService.java index 5e08cff..1f203ec 100644 --- a/src/main/java/CookSave/CookSaveback/Recipe/service/RecipeService.java +++ b/src/main/java/CookSave/CookSaveback/Recipe/service/RecipeService.java @@ -33,13 +33,16 @@ public class RecipeService { public List getRecipeList(Member member) { List recipeList = new ArrayList<>(); + // 전체 recipe 리스트 List recipes = new ArrayList<>(); recipes = recipeRepository.findAll(); int recipeCount = recipes.size(); + // 해당 member가 보유한 ingredient 리스트 List ingredients = new ArrayList<>(); ingredients = ingredientRepository.findAllByMember(member); + // 해당 member가 보유한 ingredient에 대응되는 tag의 tagId 리스트 List tags = new ArrayList<>(); for (Ingredient ingredient : ingredients) { tags.add(ingredient.getTag().getTagId()); @@ -47,12 +50,15 @@ public List getRecipeList(Member member) { } int tagCount = tags.size(); + // tags 중 각 recipe에 포함되는 태그의 개수 List 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) From a5585ca38b9dcc46b9f97eb4db64435d9ad81a32 Mon Sep 17 00:00:00 2001 From: Soyeon-Cha <7103sy@naver.com> Date: Wed, 17 Apr 2024 20:14:40 +0900 Subject: [PATCH 2/2] =?UTF-8?q?fix:=20=EC=A0=84=EC=B2=B4=20=EB=A0=88?= =?UTF-8?q?=EC=8B=9C=ED=94=BC=20=EC=A1=B0=ED=9A=8C=20=EA=B8=B0=EB=8A=A5?= =?UTF-8?q?=EC=97=90=EC=84=9C=20ingredient=EC=9D=98=20tag=EA=B0=80=20null?= =?UTF-8?q?=EC=9D=B8=20=EA=B2=BD=EC=9A=B0=20=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CookSaveback/Recipe/service/RecipeService.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/java/CookSave/CookSaveback/Recipe/service/RecipeService.java b/src/main/java/CookSave/CookSaveback/Recipe/service/RecipeService.java index 1f203ec..8996267 100644 --- a/src/main/java/CookSave/CookSaveback/Recipe/service/RecipeService.java +++ b/src/main/java/CookSave/CookSaveback/Recipe/service/RecipeService.java @@ -45,7 +45,13 @@ public List getRecipeList(Member member) { // 해당 member가 보유한 ingredient에 대응되는 tag의 tagId 리스트 List 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();