Skip to content

Commit

Permalink
refactor: 상품 자동 완성 검색 API 수정 (#74)
Browse files Browse the repository at this point in the history
* refactor: 상품 자동 완성 검색 dto 필드 추가

* refactor: 상품 자동 완성 검색 관련 dto 클래스 record로 타입 변경
  • Loading branch information
Go-Jaecheol authored Jun 7, 2024
1 parent 9324373 commit 2d36b44
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 46 deletions.
34 changes: 10 additions & 24 deletions src/main/java/com/funeat/product/dto/SearchProductDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
21 changes: 4 additions & 17 deletions src/main/java/com/funeat/product/dto/SearchProductsResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,12 @@

import java.util.List;

public class SearchProductsResponse {

private final boolean hasNext;
private final List<SearchProductDto> products;

private SearchProductsResponse(final boolean hasNext, final List<SearchProductDto> products) {
this.hasNext = hasNext;
this.products = products;
}
public record SearchProductsResponse(
boolean hasNext,
List<SearchProductDto> products
) {

public static SearchProductsResponse toResponse(final boolean hasNext, final List<SearchProductDto> products) {
return new SearchProductsResponse(hasNext, products);
}

public boolean isHasNext() {
return hasNext;
}

public List<SearchProductDto> getProducts() {
return products;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
}

Expand Down

0 comments on commit 2d36b44

Please sign in to comment.