Skip to content

Commit

Permalink
temp
Browse files Browse the repository at this point in the history
  • Loading branch information
70825 committed Mar 27, 2024
1 parent f71cfae commit 5cb45e4
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 12 deletions.
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
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

0 comments on commit 5cb45e4

Please sign in to comment.