From 7a3982de98dacee1ac8185846e342b800c19af47 Mon Sep 17 00:00:00 2001 From: Hanvp Date: Mon, 29 Jan 2024 10:14:39 +0900 Subject: [PATCH] =?UTF-8?q?:bug:=20Bug/294=20repository=20=EC=97=B0?= =?UTF-8?q?=EA=B2=B0=EC=97=90=EC=84=9C=20recipe=20->=20testRecipe=EB=93=A4?= =?UTF-8?q?=EB=A1=9C=20=EC=97=B0=EA=B2=B0=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/converter/RecipeConverter.java | 1 - .../TestRecipeRepositoryCustom.java | 1 + .../TestRecipeRepositoryImpl.java | 19 ++++++++++++++++--- .../serviceImpl/RecipeServiceImpl.java | 2 +- 4 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/main/java/zipdabang/server/converter/RecipeConverter.java b/src/main/java/zipdabang/server/converter/RecipeConverter.java index 933e54d..c60f4fb 100644 --- a/src/main/java/zipdabang/server/converter/RecipeConverter.java +++ b/src/main/java/zipdabang/server/converter/RecipeConverter.java @@ -44,7 +44,6 @@ public class RecipeConverter { private static AmazonS3Manager staticAmazonS3Manager; private static TimeConverter staticTimeConverter; - private static RecipeService staticRecipeService; diff --git a/src/main/java/zipdabang/server/repository/testRepository/testRecipeRepositoryCustom/TestRecipeRepositoryCustom.java b/src/main/java/zipdabang/server/repository/testRepository/testRecipeRepositoryCustom/TestRecipeRepositoryCustom.java index d65ec38..62ec1fa 100644 --- a/src/main/java/zipdabang/server/repository/testRepository/testRecipeRepositoryCustom/TestRecipeRepositoryCustom.java +++ b/src/main/java/zipdabang/server/repository/testRepository/testRecipeRepositoryCustom/TestRecipeRepositoryCustom.java @@ -8,6 +8,7 @@ public interface TestRecipeRepositoryCustom { + BooleanExpression recipesInCategoryCondition(Long categoryId); List testRecipesOrderBy(Integer pageIndex, Integer pageSize, String order, BooleanExpression... booleanExpressions); Long testRecipeTotalCount(BooleanExpression... booleanExpressions); diff --git a/src/main/java/zipdabang/server/repository/testRepository/testRecipeRepositoryImpl/TestRecipeRepositoryImpl.java b/src/main/java/zipdabang/server/repository/testRepository/testRecipeRepositoryImpl/TestRecipeRepositoryImpl.java index bce3534..b584813 100644 --- a/src/main/java/zipdabang/server/repository/testRepository/testRecipeRepositoryImpl/TestRecipeRepositoryImpl.java +++ b/src/main/java/zipdabang/server/repository/testRepository/testRecipeRepositoryImpl/TestRecipeRepositoryImpl.java @@ -6,13 +6,16 @@ import lombok.extern.slf4j.Slf4j; import zipdabang.server.domain.member.Member; import zipdabang.server.domain.test.QTestRecipe; +import zipdabang.server.domain.test.QTestRecipeCategoryMapping; import zipdabang.server.domain.test.TestRecipe; import zipdabang.server.repository.testRepository.testRecipeRepositoryCustom.TestRecipeRepositoryCustom; import java.util.List; import static zipdabang.server.domain.recipe.QRecipe.recipe; +import static zipdabang.server.domain.recipe.QRecipeCategoryMapping.recipeCategoryMapping; import static zipdabang.server.domain.test.QTestRecipe.testRecipe; +import static zipdabang.server.domain.test.QTestRecipeCategoryMapping.testRecipeCategoryMapping; @Slf4j @RequiredArgsConstructor @@ -20,6 +23,16 @@ public class TestRecipeRepositoryImpl implements TestRecipeRepositoryCustom { private final JPAQueryFactory queryFactory; QTestRecipe qTestRecipe = testRecipe; + QTestRecipeCategoryMapping qTestRecipeCategoryMapping = testRecipeCategoryMapping; + + @Override + public BooleanExpression recipesInCategoryCondition(Long categoryId) { + return testRecipe.in(queryFactory + .select(testRecipeCategoryMapping.recipe) + .from(testRecipeCategoryMapping) + .where(testRecipeCategoryMapping.category.id.eq(categoryId)) + .fetch()); + } @Override public List testRecipesOrderBy(Integer pageIndex, Integer pageSize, String order, BooleanExpression... booleanExpressions) { @@ -36,7 +49,7 @@ public List testRecipesOrderBy(Integer pageIndex, Integer pageSize, return queryFactory .selectFrom(testRecipe) - .orderBy(recipe.createdAt.desc()) + .orderBy(testRecipe.createdAt.desc()) .offset(pageIndex * pageSize) .limit(pageSize) .fetch(); @@ -56,8 +69,8 @@ public Long testRecipeTotalCount(BooleanExpression... booleanExpressions) { } return queryFactory - .select(recipe.count()) - .from(recipe) + .select(testRecipe.count()) + .from(testRecipe) .where( combinedExpression ) diff --git a/src/main/java/zipdabang/server/service/serviceImpl/RecipeServiceImpl.java b/src/main/java/zipdabang/server/service/serviceImpl/RecipeServiceImpl.java index 8f8359b..26f6891 100644 --- a/src/main/java/zipdabang/server/service/serviceImpl/RecipeServiceImpl.java +++ b/src/main/java/zipdabang/server/service/serviceImpl/RecipeServiceImpl.java @@ -949,7 +949,7 @@ public Page testRecipeListByCategory(Long categoryId, Integer pageIn List content = new ArrayList<>(); - BooleanExpression whereCondition = recipeRepositoryCustom.recipesInCategoryCondition(categoryId); + BooleanExpression whereCondition = testRecipeRepositoryCustom.recipesInCategoryCondition(categoryId); content = testRecipeRepositoryCustom.testRecipesOrderBy(pageIndex,pageSize, order, whereCondition);