From 2d36b4488b632c8533bc882ab38df64850d3fb20 Mon Sep 17 00:00:00 2001 From: JFe <33208246+Go-Jaecheol@users.noreply.github.com> Date: Fri, 7 Jun 2024 19:56:47 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20=EC=83=81=ED=92=88=20=EC=9E=90?= =?UTF-8?q?=EB=8F=99=20=EC=99=84=EC=84=B1=20=EA=B2=80=EC=83=89=20API=20?= =?UTF-8?q?=EC=88=98=EC=A0=95=20(#74)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * refactor: 상품 자동 완성 검색 dto 필드 추가 * refactor: 상품 자동 완성 검색 관련 dto 클래스 record로 타입 변경 --- .../funeat/product/dto/SearchProductDto.java | 34 ++++++------------- .../product/dto/SearchProductsResponse.java | 21 +++--------- .../product/ProductAcceptanceTest.java | 8 ++--- 3 files changed, 17 insertions(+), 46 deletions(-) diff --git a/src/main/java/com/funeat/product/dto/SearchProductDto.java b/src/main/java/com/funeat/product/dto/SearchProductDto.java index f41bfa11..4d7a09b6 100644 --- a/src/main/java/com/funeat/product/dto/SearchProductDto.java +++ b/src/main/java/com/funeat/product/dto/SearchProductDto.java @@ -2,31 +2,17 @@ import com.funeat.product.domain.Product; -public class SearchProductDto { - - private final Long id; - private final String name; - private final String categoryType; - - public SearchProductDto(final Long id, final String name, final String categoryType) { - this.id = id; - this.name = name; - this.categoryType = categoryType; - } +public record SearchProductDto( + Long id, + String name, + Long price, + String image, + Double averageRating, + String categoryType +) { public static SearchProductDto toDto(final Product product) { - return new SearchProductDto(product.getId(), product.getName(), product.getCategory().getType().getName()); - } - - public Long getId() { - return id; - } - - public String getName() { - return name; - } - - public String getCategoryType() { - return categoryType; + return new SearchProductDto(product.getId(), product.getName(), product.getPrice(), product.getImage(), + product.getAverageRating(), product.getCategory().getType().getName()); } } diff --git a/src/main/java/com/funeat/product/dto/SearchProductsResponse.java b/src/main/java/com/funeat/product/dto/SearchProductsResponse.java index 098c8e50..6e318748 100644 --- a/src/main/java/com/funeat/product/dto/SearchProductsResponse.java +++ b/src/main/java/com/funeat/product/dto/SearchProductsResponse.java @@ -2,25 +2,12 @@ import java.util.List; -public class SearchProductsResponse { - - private final boolean hasNext; - private final List products; - - private SearchProductsResponse(final boolean hasNext, final List products) { - this.hasNext = hasNext; - this.products = products; - } +public record SearchProductsResponse( + boolean hasNext, + List products +) { public static SearchProductsResponse toResponse(final boolean hasNext, final List products) { return new SearchProductsResponse(hasNext, products); } - - public boolean isHasNext() { - return hasNext; - } - - 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 e35b0292..465215fa 100644 --- a/src/test/java/com/funeat/acceptance/product/ProductAcceptanceTest.java +++ b/src/test/java/com/funeat/acceptance/product/ProductAcceptanceTest.java @@ -104,10 +104,8 @@ 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; @@ -451,8 +449,8 @@ class searchProducts_성공_테스트 { // when final var 응답1 = 상품_자동_완성_검색_요청("망고", 0L); - final var result = 응답1.as(SearchProductsResponse.class).getProducts(); - final var lastId = result.get(result.size() - 1).getId(); + final var result = 응답1.as(SearchProductsResponse.class).products(); + final var lastId = result.get(result.size() - 1).id(); final var 응답2 = 상품_자동_완성_검색_요청("망고", lastId); // then @@ -736,7 +734,7 @@ class getSearchResultsByTag_성공_테스트 { .getList("products", SearchProductDto.class); assertThat(actualHasNext).isEqualTo(hasNext); - assertThat(actualProducts).extracting(SearchProductDto::getId) + assertThat(actualProducts).extracting(SearchProductDto::id) .isEqualTo(productIds); }