Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: 꿀조합 검색 결과에 상품 이미지 및 평점 정보 추가 #43

Merged
merged 1 commit into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/main/java/com/funeat/recipe/dto/DetailProductRecipeDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,20 @@ public class DetailProductRecipeDto {
private final String name;
private final Long price;
private final String image;
private final Double averageRating;

private DetailProductRecipeDto(final Long id, final String name, final Long price, final String image) {
private DetailProductRecipeDto(final Long id, final String name, final Long price, final String image,
final Double averageRating) {
this.id = id;
this.name = name;
this.price = price;
this.image = image;
this.averageRating = averageRating;
}

public static DetailProductRecipeDto toDto(final Product product) {
return new DetailProductRecipeDto(product.getId(), product.getName(), product.getPrice(), product.getImage());
return new DetailProductRecipeDto(product.getId(), product.getName(), product.getPrice(), product.getImage(),
product.getAverageRating());
}

public Long getId() {
Expand All @@ -35,4 +39,8 @@ public Long getPrice() {
public String getImage() {
return image;
}

public Double getAverageRating() {
return averageRating;
}
}
13 changes: 6 additions & 7 deletions src/main/java/com/funeat/recipe/dto/SearchRecipeResultDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,19 @@
import com.funeat.recipe.domain.RecipeImage;
import java.time.LocalDateTime;
import java.util.List;
import java.util.stream.Collectors;

public class SearchRecipeResultDto {

private final Long id;
private final String image;
private final String title;
private final RecipeAuthorDto author;
private final List<ProductRecipeDto> products;
private final List<DetailProductRecipeDto> products;
private final Long favoriteCount;
private final LocalDateTime createdAt;

public SearchRecipeResultDto(final Long id, final String image, final String title, final RecipeAuthorDto author,
final List<ProductRecipeDto> products, final Long favoriteCount,
final List<DetailProductRecipeDto> products, final Long favoriteCount,
final LocalDateTime createdAt) {
this.id = id;
this.image = image;
Expand All @@ -31,9 +30,9 @@ public SearchRecipeResultDto(final Long id, final String image, final String tit

public static SearchRecipeResultDto toDto(final Recipe recipe, final List<RecipeImage> images,
final List<Product> products) {
final List<ProductRecipeDto> productRecipes = products.stream()
.map(ProductRecipeDto::toDto)
.collect(Collectors.toList());
final List<DetailProductRecipeDto> productRecipes = products.stream()
.map(DetailProductRecipeDto::toDto)
.toList();

if (images.isEmpty()) {
return new SearchRecipeResultDto(recipe.getId(), null, recipe.getTitle(),
Expand Down Expand Up @@ -61,7 +60,7 @@ public RecipeAuthorDto getAuthor() {
return author;
}

public List<ProductRecipeDto> getProducts() {
public List<DetailProductRecipeDto> getProducts() {
return products;
}

Expand Down
Loading