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: 꿀조합에 사용된 상품 정보에 상품 이미지 URL 추가 #27

Merged
merged 7 commits into from
Apr 3, 2024
32 changes: 32 additions & 0 deletions src/main/java/com/funeat/product/dto/CategoryDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.funeat.product.dto;

import com.funeat.product.domain.Category;

public class CategoryDto {

private final Long id;
private final String name;
private final String image;

private CategoryDto(final Long id, final String name, final String image) {
this.id = id;
this.name = name;
this.image = image;
}

public static CategoryDto toDto(final Category category) {
return new CategoryDto(category.getId(), category.getName(), category.getImage());
}

public Long getId() {
return id;
}

public String getName() {
return name;
}

public String getImage() {
return image;
}
}
17 changes: 13 additions & 4 deletions src/main/java/com/funeat/product/dto/ProductResponse.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.funeat.product.dto;

import com.funeat.product.domain.Category;
import com.funeat.product.domain.CategoryType;
import com.funeat.product.domain.Product;
import com.funeat.tag.domain.Tag;
import com.funeat.tag.dto.TagDto;
Expand All @@ -15,27 +17,30 @@ public class ProductResponse {
private final String content;
private final Double averageRating;
private final Long reviewCount;
private final CategoryDto category;
private final List<TagDto> tags;

public ProductResponse(final Long id, final String name, final Long price, final String image, final String content,
final Double averageRating, final Long reviewCount, final List<TagDto> tags) {
final Double averageRating, final Long reviewCount, final CategoryDto category, final List<TagDto> tags) {
this.id = id;
this.name = name;
this.price = price;
this.image = image;
this.content = content;
this.averageRating = averageRating;
this.reviewCount = reviewCount;
this.category = category;
this.tags = tags;
}

public static ProductResponse toResponse(final Product product, final List<Tag> tags) {
List<TagDto> tagDtos = new ArrayList<>();
for (Tag tag : tags) {
final CategoryDto categoryDto = CategoryDto.toDto(product.getCategory());
final List<TagDto> tagDtos = new ArrayList<>();
for (final Tag tag : tags) {
tagDtos.add(TagDto.toDto(tag));
}
return new ProductResponse(product.getId(), product.getName(), product.getPrice(), product.getImage(),
product.getContent(), product.getAverageRating(), product.getReviewCount(), tagDtos);
product.getContent(), product.getAverageRating(), product.getReviewCount(), categoryDto, tagDtos);
}

public Long getId() {
Expand Down Expand Up @@ -66,6 +71,10 @@ public Long getReviewCount() {
return reviewCount;
}

public CategoryDto getCategory() {
return category;
}

public List<TagDto> getTags() {
return tags;
}
Expand Down
38 changes: 38 additions & 0 deletions src/main/java/com/funeat/recipe/dto/DetailProductRecipeDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.funeat.recipe.dto;

import com.funeat.product.domain.Product;

public class DetailProductRecipeDto {

private final Long id;
private final String name;
private final Long price;
private final String image;

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

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

public Long getId() {
return id;
}

public String getName() {
return name;
}

public Long getPrice() {
return price;
}

public String getImage() {
return image;
}
}
11 changes: 6 additions & 5 deletions src/main/java/com/funeat/recipe/dto/RecipeDetailResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.funeat.product.domain.Product;
import com.funeat.recipe.domain.Recipe;
import com.funeat.recipe.domain.RecipeImage;

import java.time.LocalDateTime;
import java.util.List;
import java.util.stream.Collectors;
Expand All @@ -14,14 +15,14 @@ public class RecipeDetailResponse {
private final String title;
private final String content;
private final RecipeAuthorDto author;
private final List<ProductRecipeDto> products;
private final List<DetailProductRecipeDto> products;
private final Long totalPrice;
private final Long favoriteCount;
private final Boolean favorite;
private final LocalDateTime createdAt;

public RecipeDetailResponse(final Long id, final List<String> images, final String title, final String content,
final RecipeAuthorDto author, final List<ProductRecipeDto> products,
final RecipeAuthorDto author, final List<DetailProductRecipeDto> products,
final Long totalPrice, final Long favoriteCount, final Boolean favorite,
final LocalDateTime createdAt) {
this.id = id;
Expand All @@ -40,8 +41,8 @@ public static RecipeDetailResponse toResponse(final Recipe recipe, final List<Re
final List<Product> products, final Long totalPrice,
final Boolean favorite) {
final RecipeAuthorDto authorDto = RecipeAuthorDto.toDto(recipe.getMember());
final List<ProductRecipeDto> productDtos = products.stream()
.map(ProductRecipeDto::toDto)
final List<DetailProductRecipeDto> productDtos = products.stream()
.map(DetailProductRecipeDto::toDto)
.collect(Collectors.toList());
final List<String> images = recipeImages.stream()
.map(RecipeImage::getImage)
Expand Down Expand Up @@ -70,7 +71,7 @@ public RecipeAuthorDto getAuthor() {
return author;
}

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,19 +91,15 @@

import com.funeat.acceptance.common.AcceptanceTest;
import com.funeat.product.domain.Category;
import com.funeat.product.dto.ProductInCategoryDto;
import com.funeat.product.dto.ProductResponse;
import com.funeat.product.dto.RankingProductDto;
import com.funeat.product.dto.SearchProductDto;
import com.funeat.product.dto.SearchProductResultDto;
import com.funeat.product.dto.SearchProductResultsResponse;
import com.funeat.product.dto.SearchProductsResponse;
import com.funeat.product.dto.*;
import com.funeat.recipe.dto.RecipeDto;
import com.funeat.tag.dto.TagDto;
import io.restassured.response.ExtractableResponse;
import io.restassured.response.Response;

import java.util.Collections;
import java.util.List;

import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;

Expand Down Expand Up @@ -673,6 +669,7 @@ class getProductRecipes_성공_테스트 {

private void 상품_상세_정보_조회_결과를_검증한다(final ExtractableResponse<Response> response) {
final var actual = response.as(ProductResponse.class);
final var actualCategory = response.jsonPath().getObject("category", CategoryDto.class);
final var actualTags = response.jsonPath()
.getList("tags", TagDto.class);

Expand All @@ -684,6 +681,7 @@ class getProductRecipes_성공_테스트 {
soft.assertThat(actual.getContent()).isEqualTo("맛있는 삼각김밥");
soft.assertThat(actual.getAverageRating()).isEqualTo(3.0);
soft.assertThat(actual.getReviewCount()).isEqualTo(3L);
soft.assertThat(actualCategory.getName()).isEqualTo("간편식사");
soft.assertThat(actualTags).extracting("id").containsExactly(2L, 1L);
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ public class ProductSteps {

public static ExtractableResponse<Response> 상품_상세_조회_요청(final Long productId) {
return given()
.log().all()
.when()
.get("/api/products/{product_id}", productId)
.then()
.then().log().all()
.extract();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
import com.funeat.acceptance.common.AcceptanceTest;
import com.funeat.member.domain.Member;
import com.funeat.recipe.domain.Recipe;
import com.funeat.recipe.dto.ProductRecipeDto;
import com.funeat.recipe.dto.DetailProductRecipeDto;
import com.funeat.recipe.dto.RankingRecipeDto;
import com.funeat.recipe.dto.RecipeAuthorDto;
import com.funeat.recipe.dto.RecipeCommentCondition;
Expand Down Expand Up @@ -743,7 +743,7 @@ class getRecipeComment_실패_테스트 {
private void 레시피_상세_정보_조회_결과를_검증한다(final ExtractableResponse<Response> response) {
final var actual = response.as(RecipeDetailResponse.class);
final var actualAuthor = response.jsonPath().getObject("author", RecipeAuthorDto.class);
final var actualProducts = response.jsonPath().getList("products", ProductRecipeDto.class);
final var actualProducts = response.jsonPath().getList("products", DetailProductRecipeDto.class);

assertSoftly(soft -> {
soft.assertThat(actual.getId()).isEqualTo(1L);
Expand All @@ -755,7 +755,7 @@ class getRecipeComment_실패_테스트 {
soft.assertThat(actual.getFavorite()).isEqualTo(false);
soft.assertThat(actualAuthor.getNickname()).isEqualTo("member1");
soft.assertThat(actualAuthor.getProfileImage()).isEqualTo("www.member1.com");
soft.assertThat(actualProducts).extracting(ProductRecipeDto::getId)
soft.assertThat(actualProducts).extracting(DetailProductRecipeDto::getId)
.containsExactlyElementsOf(List.of(1L, 2L));
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,14 @@
import com.funeat.review.exception.ReviewException.NotAuthorOfReviewException;
import com.funeat.review.exception.ReviewException.ReviewNotFoundException;
import com.funeat.tag.domain.Tag;

import java.time.LocalDateTime;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;

Expand Down Expand Up @@ -1066,7 +1068,7 @@ class getReviewDetail_실패_테스트 {
.isInstanceOf(ReviewNotFoundException.class);
}
}

@Nested
class getTopReviews_성공_테스트 {

Expand Down
Loading