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: 상품 자동 완성 검색 API 수정 #74

Merged
merged 2 commits into from
Jun 7, 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
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 @@ -99,15 +99,12 @@
import com.funeat.product.dto.SearchProductResultDto;
import com.funeat.product.dto.SearchProductResultsResponse;
import com.funeat.product.dto.SearchProductsResponse;
import com.funeat.product.dto.CategoryDto;
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 @@ -451,8 +448,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 @@ -710,7 +707,7 @@ class getProductRecipes_성공_테스트 {
.getList("products", SearchProductDto.class);

assertThat(actualHasNext).isEqualTo(hasNext);
assertThat(actualProducts).extracting(SearchProductDto::getId)
assertThat(actualProducts).extracting(SearchProductDto::id)
.isEqualTo(productIds);
}

Expand Down