-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: PrimaryIngredient, Functionality 엔티티 분리 (#167)
* refactor: 동적 조회, 정적 조회 분리 * refactor: data.sql 실행 방지 * refactor: PetFoodController 인수 테스트 리팩터링 * refactor: 테스트 코드 리팩터링 및 사용하지 않는 코드 제거 * chore: MemberRepositoryTest 주석 제거 * refactor: 연관관계 편의 메소드 PetFood 안에서 처리 * refactor: Review 도메인 이름 복수형으로 변경 * refactor: reformatting code * chore: AutoConfigureTestDatabase 제거 * chore: 사용하지 않는 테스트 제거 * chore: ddl auto 옵션 변경 * refactor: BrandFixture 메소드 네이밍 수정 * fix: 이상 반응 추가 * fix: 영양기준 필터링 수정 * fix: 이상반응 추가 * feat: 테스트 추가 * chore: 데이터 수정 및 리뷰 추가 * chore: 사용하지 않는 Import 제거
- Loading branch information
1 parent
02d7381
commit f6a302e
Showing
67 changed files
with
687 additions
and
841 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,5 @@ | ||
GET http://localhost:8080/pet-foods/filters | ||
|
||
### | ||
|
||
GET http://localhost:8080/pet-foods/filters/test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
backend/src/main/java/zipgo/auth/presentation/BearerTokenExtractor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
package zipgo.auth.presentation.dto; | ||
|
||
public record AuthDto ( | ||
public record AuthDto( | ||
Long id | ||
) { | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
backend/src/main/java/zipgo/member/exception/MemberException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 6 additions & 76 deletions
82
backend/src/main/java/zipgo/petfood/application/PetFoodQueryService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,107 +1,37 @@ | ||
package zipgo.petfood.application; | ||
|
||
import static java.util.Arrays.asList; | ||
|
||
import java.util.Collection; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
import zipgo.brand.domain.Brand; | ||
import zipgo.brand.domain.repository.BrandRepository; | ||
import zipgo.petfood.domain.HasStandard; | ||
import zipgo.petfood.domain.PetFood; | ||
import zipgo.petfood.domain.repository.PetFoodQueryRepository; | ||
import zipgo.petfood.domain.repository.PetFoodRepository; | ||
import zipgo.petfood.presentation.dto.FilterResponse; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Transactional(readOnly = true) | ||
public class PetFoodQueryService { | ||
|
||
private final BrandRepository brandRepository; | ||
private final PetFoodRepository petFoodRepository; | ||
private final PetFoodQueryRepository petFoodQueryRepository; | ||
|
||
public List<PetFood> getPetFoods( | ||
public List<PetFood> getPetFoodsByFilters( | ||
List<String> brandsName, | ||
List<String> nutritionStandards, | ||
List<String> primaryIngredientList, | ||
List<String> functionalityList | ||
) { | ||
return petFoodRepository.findAll().stream() | ||
.filter(petFood -> isValidStandard(nutritionStandards, petFood.getHasStandard()) | ||
&& isContainBrandsName(brandsName, petFood.getBrand().getName()) | ||
&& isContainMainIngredients(petFood.getPrimaryIngredients(), primaryIngredientList) | ||
&& isContainFunctionalities(petFood.getFunctionality(), functionalityList)) | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
private boolean isContainBrandsName(List<String> brandsName, String brandName) { | ||
if (brandsName.isEmpty()) { | ||
return true; | ||
} | ||
return brandsName.contains(brandName); | ||
} | ||
|
||
private boolean isValidStandard(List<String> nutrientStandards, HasStandard hasStandard) { | ||
if (nutrientStandards.isEmpty()) { | ||
return true; | ||
} | ||
boolean isValid = true; | ||
for (String nutrientStandard : nutrientStandards) { | ||
if (nutrientStandard.equals("유럽") && !hasStandard.getEurope()) { | ||
isValid = false; | ||
} | ||
if (nutrientStandard.equals("미국") && !hasStandard.getUnitedStates()) { | ||
isValid = false; | ||
} | ||
} | ||
return isValid; | ||
} | ||
|
||
private boolean isContainMainIngredients(List<String> primaryIngredients, List<String> primaryIngredientList) { | ||
if (primaryIngredientList.isEmpty()) { | ||
return true; | ||
} | ||
return primaryIngredientList.stream() | ||
.anyMatch(it -> primaryIngredients.contains(it)); | ||
} | ||
|
||
private boolean isContainFunctionalities(List<String> functionalities, List<String> functionalityList) { | ||
if (functionalityList.isEmpty()) { | ||
return true; | ||
} | ||
return functionalities.stream() | ||
.anyMatch(it -> functionalities.contains(it)); | ||
} | ||
|
||
public List<PetFood> getPetFoodByDynamicValue(String keyword, String brand, String primaryIngredients) { | ||
return petFoodQueryRepository.findPetFoods(keyword, brand, primaryIngredients); | ||
return petFoodQueryRepository.findPetFoods(brandsName, nutritionStandards, primaryIngredientList, | ||
functionalityList); | ||
} | ||
|
||
public PetFood getPetFoodBy(Long id) { | ||
return petFoodRepository.getById(id); | ||
} | ||
|
||
public FilterResponse getMetadataForFilter() { | ||
List<Brand> brands = brandRepository.findAll(); | ||
|
||
List<String> primaryIngredients = petFoodRepository.findAllPrimaryIngredients().stream() | ||
.map(primaryIngredient -> asList(primaryIngredient.split(","))) | ||
.flatMap(Collection::stream) | ||
.distinct() | ||
.toList(); | ||
|
||
List<String> functionalities = petFoodRepository.findAllFunctionalities().stream() | ||
.map(functionality -> asList(functionality.split(","))) | ||
.flatMap(Collection::stream) | ||
.distinct() | ||
.toList(); | ||
|
||
return FilterResponse.from(brands, primaryIngredients, functionalities); | ||
} | ||
// public FilterResponse getMetadataForFilter() { | ||
// return null; | ||
// } | ||
|
||
} |
37 changes: 25 additions & 12 deletions
37
backend/src/main/java/zipgo/petfood/domain/Functionality.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,39 @@ | ||
package zipgo.petfood.domain; | ||
|
||
import jakarta.persistence.Convert; | ||
import jakarta.persistence.Embeddable; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.FetchType; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.JoinColumn; | ||
import jakarta.persistence.ManyToOne; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Builder.Default; | ||
import lombok.EqualsAndHashCode; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
import static jakarta.persistence.GenerationType.IDENTITY; | ||
import static lombok.AccessLevel.PROTECTED; | ||
|
||
@Entity | ||
@Getter | ||
@Builder | ||
@Embeddable | ||
@EqualsAndHashCode | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@NoArgsConstructor(access = PROTECTED) | ||
public class Functionality { | ||
|
||
@Default | ||
@Convert(converter = StringArrayConverter.class) | ||
private List<String> functionality = new ArrayList<>(); | ||
@Id | ||
@GeneratedValue(strategy = IDENTITY) | ||
private Long id; | ||
|
||
private String name; | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "pet_food_id") | ||
private PetFood petFood; | ||
|
||
public void changePetFood(PetFood petFood) { | ||
this.petFood = petFood; | ||
this.petFood.addFunctionality(this); | ||
} | ||
|
||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.