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.주원료_닭고기;