From 19974fbdce1213aea35526cd42a187e10104ec93 Mon Sep 17 00:00:00 2001 From: wonyongChoi05 Date: Wed, 16 Aug 2023 12:59:43 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=EB=8D=B0=EC=9D=B4=ED=84=B0=20=EC=A4=91?= =?UTF-8?q?=EB=B3=B5=20=EC=A0=9C=EA=B1=B0=20=EC=A0=84=20limit=EC=9D=84=20?= =?UTF-8?q?=EA=B1=B0=EB=8A=94=20=EB=AC=B8=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../infra/persist/PetFoodQueryRepository.java | 3 ++- .../auth/presentation/AuthControllerTest.java | 1 - .../presentaion/ImageControllerTest.java | 2 -- .../persist/PetFoodQueryRepositoryTest.java | 25 +++++++++++++++++++ .../presentation/PetFoodControllerTest.java | 3 +-- 5 files changed, 28 insertions(+), 6 deletions(-) diff --git a/backend/src/main/java/zipgo/petfood/infra/persist/PetFoodQueryRepository.java b/backend/src/main/java/zipgo/petfood/infra/persist/PetFoodQueryRepository.java index 077827193..a26d8d7e1 100644 --- a/backend/src/main/java/zipgo/petfood/infra/persist/PetFoodQueryRepository.java +++ b/backend/src/main/java/zipgo/petfood/infra/persist/PetFoodQueryRepository.java @@ -29,7 +29,8 @@ public List findPagingPetFoods( int size ) { return queryFactory - .selectFrom(petFood) + .selectDistinct(petFood) + .from(petFood) .join(petFood.brand, brand) .fetchJoin() .join(petFood.petFoodPrimaryIngredients, petFoodPrimaryIngredient) diff --git a/backend/src/test/java/zipgo/auth/presentation/AuthControllerTest.java b/backend/src/test/java/zipgo/auth/presentation/AuthControllerTest.java index f47d7bfd6..4d110f115 100644 --- a/backend/src/test/java/zipgo/auth/presentation/AuthControllerTest.java +++ b/backend/src/test/java/zipgo/auth/presentation/AuthControllerTest.java @@ -10,7 +10,6 @@ import org.springframework.boot.test.autoconfigure.restdocs.AutoConfigureRestDocs; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.data.jpa.mapping.JpaMetamodelMappingContext; import org.springframework.restdocs.mockmvc.RestDocumentationResultHandler; import org.springframework.restdocs.payload.JsonFieldType; import org.springframework.test.context.junit.jupiter.SpringExtension; diff --git a/backend/src/test/java/zipgo/image/presentaion/ImageControllerTest.java b/backend/src/test/java/zipgo/image/presentaion/ImageControllerTest.java index 7e9d32796..14ce0721b 100644 --- a/backend/src/test/java/zipgo/image/presentaion/ImageControllerTest.java +++ b/backend/src/test/java/zipgo/image/presentaion/ImageControllerTest.java @@ -9,10 +9,8 @@ import org.springframework.boot.test.autoconfigure.restdocs.AutoConfigureRestDocs; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.data.jpa.mapping.JpaMetamodelMappingContext; import org.springframework.http.MediaType; import org.springframework.mock.web.MockMultipartFile; -import org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders; import org.springframework.restdocs.mockmvc.RestDocumentationResultHandler; import org.springframework.restdocs.payload.JsonFieldType; import org.springframework.test.context.junit.jupiter.SpringExtension; diff --git a/backend/src/test/java/zipgo/petfood/infra/persist/PetFoodQueryRepositoryTest.java b/backend/src/test/java/zipgo/petfood/infra/persist/PetFoodQueryRepositoryTest.java index f603a89ea..a7cb08709 100644 --- a/backend/src/test/java/zipgo/petfood/infra/persist/PetFoodQueryRepositoryTest.java +++ b/backend/src/test/java/zipgo/petfood/infra/persist/PetFoodQueryRepositoryTest.java @@ -33,6 +33,7 @@ import static zipgo.petfood.domain.fixture.PetFoodIngredientFixture.식품_주원료_연관관계_매핑; import static zipgo.petfood.domain.fixture.PrimaryIngredientFixture.주원료_닭고기; import static zipgo.petfood.domain.fixture.PrimaryIngredientFixture.주원료_돼지고기; +import static zipgo.petfood.domain.fixture.PrimaryIngredientFixture.주원료_말미잘; import static zipgo.petfood.domain.fixture.PrimaryIngredientFixture.주원료_소고기; @Transactional @@ -120,4 +121,28 @@ void setUp() { ); } + @Test + void 같은_식품을_제거하고_limit_개수만큼_반환한다() { + // given + List allFoods = petFoodRepository.findAll(); + Long lastPetFoodId = allFoods.get(allFoods.size() - 1).getId(); + + PetFood petFood = petFoodRepository.getById(lastPetFoodId); + 식품_기능성_연관관계_매핑(petFood, 기능성_다이어트()); + 식품_주원료_연관관계_매핑(petFood, 주원료_말미잘()); + petFoodRepository.save(petFood); + + List brandsName = EMPTY_LIST; + List standards = EMPTY_LIST; + List primaryIngredientList = EMPTY_LIST; + List functionalityList = EMPTY_LIST; + + // when + List petFoods = petFoodQueryRepository.findPagingPetFoods(brandsName, standards, primaryIngredientList, + functionalityList, lastPetFoodId, 20); + + // then + assertThat(petFoods).hasSize(3); + } + } diff --git a/backend/src/test/java/zipgo/petfood/presentation/PetFoodControllerTest.java b/backend/src/test/java/zipgo/petfood/presentation/PetFoodControllerTest.java index 22c8737bb..17bed4dd9 100644 --- a/backend/src/test/java/zipgo/petfood/presentation/PetFoodControllerTest.java +++ b/backend/src/test/java/zipgo/petfood/presentation/PetFoodControllerTest.java @@ -16,7 +16,6 @@ import zipgo.petfood.domain.Functionality; import zipgo.petfood.domain.PetFood; import zipgo.petfood.domain.PrimaryIngredient; -import zipgo.petfood.domain.fixture.PetFoodFunctionalityFixture; import zipgo.petfood.domain.repository.FunctionalityRepository; import zipgo.petfood.domain.repository.PetFoodRepository; import zipgo.petfood.domain.repository.PrimaryIngredientRepository; @@ -42,7 +41,7 @@ import static zipgo.petfood.domain.fixture.FunctionalityFixture.기능성_다이어트; import static zipgo.petfood.domain.fixture.FunctionalityFixture.기능성_튼튼; import static zipgo.petfood.domain.fixture.PetFoodFixture.모든_영양기준_만족_식품; -import static zipgo.petfood.domain.fixture.PetFoodFunctionalityFixture.*; +import static zipgo.petfood.domain.fixture.PetFoodFunctionalityFixture.식품_기능성_연관관계_매핑; import static zipgo.petfood.domain.fixture.PetFoodIngredientFixture.식품_주원료_연관관계_매핑; import static zipgo.petfood.domain.fixture.PrimaryIngredientFixture.주원료_닭고기;