Skip to content

Commit

Permalink
fix: 데이터 중복 제거 전 limit을 거는 문제
Browse files Browse the repository at this point in the history
  • Loading branch information
wonyongChoi05 committed Aug 16, 2023
1 parent 56d4dd7 commit 19974fb
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ public List<PetFood> findPagingPetFoods(
int size
) {
return queryFactory
.selectFrom(petFood)
.selectDistinct(petFood)
.from(petFood)
.join(petFood.brand, brand)
.fetchJoin()
.join(petFood.petFoodPrimaryIngredients, petFoodPrimaryIngredient)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -120,4 +121,28 @@ void setUp() {
);
}

@Test
void 같은_식품을_제거하고_limit_개수만큼_반환한다() {
// given
List<PetFood> allFoods = petFoodRepository.findAll();
Long lastPetFoodId = allFoods.get(allFoods.size() - 1).getId();

PetFood petFood = petFoodRepository.getById(lastPetFoodId);
식품_기능성_연관관계_매핑(petFood, 기능성_다이어트());
식품_주원료_연관관계_매핑(petFood, 주원료_말미잘());
petFoodRepository.save(petFood);

List<String> brandsName = EMPTY_LIST;
List<String> standards = EMPTY_LIST;
List<String> primaryIngredientList = EMPTY_LIST;
List<String> functionalityList = EMPTY_LIST;

// when
List<PetFood> petFoods = petFoodQueryRepository.findPagingPetFoods(brandsName, standards, primaryIngredientList,
functionalityList, lastPetFoodId, 20);

// then
assertThat(petFoods).hasSize(3);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.주원료_닭고기;

Expand Down

0 comments on commit 19974fb

Please sign in to comment.