From 255f868fb8e4bfe51d93f72b8a528c4404acc77e Mon Sep 17 00:00:00 2001 From: Dabeen Jeong Date: Wed, 3 Apr 2024 10:17:43 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20=EA=BF=80=EC=A1=B0=ED=95=A9?= =?UTF-8?q?=EC=97=90=20=EC=82=AC=EC=9A=A9=EB=90=9C=20=EC=83=81=ED=92=88=20?= =?UTF-8?q?=EC=A0=95=EB=B3=B4=EC=97=90=20=EC=83=81=ED=92=88=20=EC=9D=B4?= =?UTF-8?q?=EB=AF=B8=EC=A7=80=20URL=20=EC=B6=94=EA=B0=80=20(#27)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: 레시피 안에 있는 상품들의 상품 이미지 링크 추가 * refactor: 레시피에 사용된 상품 정보를 새로운 DTO로 사용하면서 검증할 DTO 수정 * refactor: 최신순으로 리뷰 목록 조회 저장 로직 수정 * temp * refactor: 빈줄 제거, import문 와일드카드 제거 * refactor: 최신순으로 정렬해서 리뷰 목록을 확인하는 테스트를 롤백 * refactor: import문 와일드카드 제거 --- .../com/funeat/product/dto/CategoryDto.java | 32 ++++++++++++++++ .../funeat/product/dto/ProductResponse.java | 17 +++++++-- .../recipe/dto/DetailProductRecipeDto.java | 38 +++++++++++++++++++ .../recipe/dto/RecipeDetailResponse.java | 11 +++--- .../product/ProductAcceptanceTest.java | 5 +++ .../acceptance/product/ProductSteps.java | 3 +- .../recipe/RecipeAcceptanceTest.java | 6 +-- .../review/application/ReviewServiceTest.java | 2 +- 8 files changed, 100 insertions(+), 14 deletions(-) create mode 100644 src/main/java/com/funeat/product/dto/CategoryDto.java create mode 100644 src/main/java/com/funeat/recipe/dto/DetailProductRecipeDto.java diff --git a/src/main/java/com/funeat/product/dto/CategoryDto.java b/src/main/java/com/funeat/product/dto/CategoryDto.java new file mode 100644 index 00000000..13fa0121 --- /dev/null +++ b/src/main/java/com/funeat/product/dto/CategoryDto.java @@ -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; + } +} diff --git a/src/main/java/com/funeat/product/dto/ProductResponse.java b/src/main/java/com/funeat/product/dto/ProductResponse.java index d3c0ed26..8dbf1095 100644 --- a/src/main/java/com/funeat/product/dto/ProductResponse.java +++ b/src/main/java/com/funeat/product/dto/ProductResponse.java @@ -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; @@ -15,10 +17,11 @@ public class ProductResponse { private final String content; private final Double averageRating; private final Long reviewCount; + private final CategoryDto category; private final List 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 tags) { + final Double averageRating, final Long reviewCount, final CategoryDto category, final List tags) { this.id = id; this.name = name; this.price = price; @@ -26,16 +29,18 @@ public ProductResponse(final Long id, final String name, final Long price, final this.content = content; this.averageRating = averageRating; this.reviewCount = reviewCount; + this.category = category; this.tags = tags; } public static ProductResponse toResponse(final Product product, final List tags) { - List tagDtos = new ArrayList<>(); - for (Tag tag : tags) { + final CategoryDto categoryDto = CategoryDto.toDto(product.getCategory()); + final List 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() { @@ -66,6 +71,10 @@ public Long getReviewCount() { return reviewCount; } + public CategoryDto getCategory() { + return category; + } + public List getTags() { return tags; } diff --git a/src/main/java/com/funeat/recipe/dto/DetailProductRecipeDto.java b/src/main/java/com/funeat/recipe/dto/DetailProductRecipeDto.java new file mode 100644 index 00000000..65cf4f3a --- /dev/null +++ b/src/main/java/com/funeat/recipe/dto/DetailProductRecipeDto.java @@ -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; + } +} diff --git a/src/main/java/com/funeat/recipe/dto/RecipeDetailResponse.java b/src/main/java/com/funeat/recipe/dto/RecipeDetailResponse.java index 6ccef941..d0062d48 100644 --- a/src/main/java/com/funeat/recipe/dto/RecipeDetailResponse.java +++ b/src/main/java/com/funeat/recipe/dto/RecipeDetailResponse.java @@ -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; @@ -14,14 +15,14 @@ public class RecipeDetailResponse { private final String title; private final String content; private final RecipeAuthorDto author; - private final List products; + private final List products; private final Long totalPrice; private final Long favoriteCount; private final Boolean favorite; private final LocalDateTime createdAt; public RecipeDetailResponse(final Long id, final List images, final String title, final String content, - final RecipeAuthorDto author, final List products, + final RecipeAuthorDto author, final List products, final Long totalPrice, final Long favoriteCount, final Boolean favorite, final LocalDateTime createdAt) { this.id = id; @@ -40,8 +41,8 @@ public static RecipeDetailResponse toResponse(final Recipe recipe, final List products, final Long totalPrice, final Boolean favorite) { final RecipeAuthorDto authorDto = RecipeAuthorDto.toDto(recipe.getMember()); - final List productDtos = products.stream() - .map(ProductRecipeDto::toDto) + final List productDtos = products.stream() + .map(DetailProductRecipeDto::toDto) .collect(Collectors.toList()); final List images = recipeImages.stream() .map(RecipeImage::getImage) @@ -70,7 +71,7 @@ public RecipeAuthorDto getAuthor() { return author; } - public List getProducts() { + public List getProducts() { return products; } diff --git a/src/test/java/com/funeat/acceptance/product/ProductAcceptanceTest.java b/src/test/java/com/funeat/acceptance/product/ProductAcceptanceTest.java index 87c0d300..8e301277 100644 --- a/src/test/java/com/funeat/acceptance/product/ProductAcceptanceTest.java +++ b/src/test/java/com/funeat/acceptance/product/ProductAcceptanceTest.java @@ -91,6 +91,7 @@ import com.funeat.acceptance.common.AcceptanceTest; import com.funeat.product.domain.Category; +import com.funeat.product.dto.CategoryDto; import com.funeat.product.dto.ProductInCategoryDto; import com.funeat.product.dto.ProductResponse; import com.funeat.product.dto.RankingProductDto; @@ -102,8 +103,10 @@ 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; @@ -673,6 +676,7 @@ class getProductRecipes_성공_테스트 { private void 상품_상세_정보_조회_결과를_검증한다(final ExtractableResponse 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); @@ -684,6 +688,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); }); } diff --git a/src/test/java/com/funeat/acceptance/product/ProductSteps.java b/src/test/java/com/funeat/acceptance/product/ProductSteps.java index 512f4f5a..8c989c2a 100644 --- a/src/test/java/com/funeat/acceptance/product/ProductSteps.java +++ b/src/test/java/com/funeat/acceptance/product/ProductSteps.java @@ -21,9 +21,10 @@ public class ProductSteps { public static ExtractableResponse 상품_상세_조회_요청(final Long productId) { return given() + .log().all() .when() .get("/api/products/{product_id}", productId) - .then() + .then().log().all() .extract(); } diff --git a/src/test/java/com/funeat/acceptance/recipe/RecipeAcceptanceTest.java b/src/test/java/com/funeat/acceptance/recipe/RecipeAcceptanceTest.java index 57198ace..e92c91c3 100644 --- a/src/test/java/com/funeat/acceptance/recipe/RecipeAcceptanceTest.java +++ b/src/test/java/com/funeat/acceptance/recipe/RecipeAcceptanceTest.java @@ -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; @@ -743,7 +743,7 @@ class getRecipeComment_실패_테스트 { private void 레시피_상세_정보_조회_결과를_검증한다(final ExtractableResponse 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); @@ -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)); }); } diff --git a/src/test/java/com/funeat/review/application/ReviewServiceTest.java b/src/test/java/com/funeat/review/application/ReviewServiceTest.java index 93fd0e04..ac67cd34 100644 --- a/src/test/java/com/funeat/review/application/ReviewServiceTest.java +++ b/src/test/java/com/funeat/review/application/ReviewServiceTest.java @@ -1066,7 +1066,7 @@ class getReviewDetail_실패_테스트 { .isInstanceOf(ReviewNotFoundException.class); } } - + @Nested class getTopReviews_성공_테스트 {