From 3d01ae3977ac85cccbbb0dbf94e5f78a0f78090c Mon Sep 17 00:00:00 2001 From: JFe <33208246+Go-Jaecheol@users.noreply.github.com> Date: Fri, 15 Sep 2023 14:44:57 +0900 Subject: [PATCH] =?UTF-8?q?[BE]=20feat:=20=EC=B9=B4=ED=85=8C=EA=B3=A0?= =?UTF-8?q?=EB=A6=AC=20=EC=9D=B4=EB=AF=B8=EC=A7=80=20=EC=B6=94=EA=B0=80=20?= =?UTF-8?q?(#638)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: Category에 image 추가 * feat: CategoryResponse에 image 추가 --- .../com/funeat/product/domain/Category.java | 16 ++++---- .../funeat/product/dto/CategoryResponse.java | 10 ++++- .../com/funeat/fixture/CategoryFixture.java | 20 ++++----- .../recipe/application/RecipeServiceTest.java | 41 +++++++------------ 4 files changed, 42 insertions(+), 45 deletions(-) diff --git a/backend/src/main/java/com/funeat/product/domain/Category.java b/backend/src/main/java/com/funeat/product/domain/Category.java index 03d1d4f52..5d6c62a08 100644 --- a/backend/src/main/java/com/funeat/product/domain/Category.java +++ b/backend/src/main/java/com/funeat/product/domain/Category.java @@ -1,11 +1,6 @@ package com.funeat.product.domain; -import javax.persistence.Entity; -import javax.persistence.EnumType; -import javax.persistence.Enumerated; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; +import javax.persistence.*; @Entity public class Category { @@ -19,12 +14,15 @@ public class Category { @Enumerated(EnumType.STRING) private CategoryType type; + private String image; + protected Category() { } - public Category(final String name, final CategoryType type) { + public Category(final String name, final CategoryType type, final String image) { this.name = name; this.type = type; + this.image = image; } public Long getId() { @@ -38,4 +36,8 @@ public String getName() { public CategoryType getType() { return type; } + + public String getImage() { + return image; + } } diff --git a/backend/src/main/java/com/funeat/product/dto/CategoryResponse.java b/backend/src/main/java/com/funeat/product/dto/CategoryResponse.java index ebf70e602..3ea9e59a5 100644 --- a/backend/src/main/java/com/funeat/product/dto/CategoryResponse.java +++ b/backend/src/main/java/com/funeat/product/dto/CategoryResponse.java @@ -6,14 +6,16 @@ public class CategoryResponse { private final Long id; private final String name; + private final String image; - public CategoryResponse(final Long id, final String name) { + public CategoryResponse(final Long id, final String name, final String image) { this.id = id; this.name = name; + this.image = image; } public static CategoryResponse toResponse(final Category category) { - return new CategoryResponse(category.getId(), category.getName()); + return new CategoryResponse(category.getId(), category.getName(), category.getImage()); } public Long getId() { @@ -23,4 +25,8 @@ public Long getId() { public String getName() { return name; } + + public String getImage() { + return image; + } } diff --git a/backend/src/test/java/com/funeat/fixture/CategoryFixture.java b/backend/src/test/java/com/funeat/fixture/CategoryFixture.java index b41401ce3..9d6da56ab 100644 --- a/backend/src/test/java/com/funeat/fixture/CategoryFixture.java +++ b/backend/src/test/java/com/funeat/fixture/CategoryFixture.java @@ -7,42 +7,42 @@ public class CategoryFixture { public static Category 카테고리_간편식사_생성() { - return new Category("간편식사", CategoryType.FOOD); + return new Category("간편식사", CategoryType.FOOD, "siksa.jpeg"); } public static Category 카테고리_즉석조리_생성() { - return new Category("즉석조리", CategoryType.FOOD); + return new Category("즉석조리", CategoryType.FOOD, "direct.jpeg"); } public static Category 카테고리_과자류_생성() { - return new Category("과자류", CategoryType.FOOD); + return new Category("과자류", CategoryType.FOOD, "snack.jpeg"); } public static Category 카테고리_아이스크림_생성() { - return new Category("아이스크림", CategoryType.FOOD); + return new Category("아이스크림", CategoryType.FOOD, "ice.jpeg"); } public static Category 카테고리_식품_생성() { - return new Category("식품", CategoryType.FOOD); + return new Category("식품", CategoryType.FOOD, "food.jpeg"); } public static Category 카테고리_음료_생성() { - return new Category("음료", CategoryType.FOOD); + return new Category("음료", CategoryType.FOOD, "drink.jpeg"); } public static Category 카테고리_CU_생성() { - return new Category("CU", CategoryType.STORE); + return new Category("CU", CategoryType.STORE, "cu.jpeg"); } public static Category 카테고리_GS25_생성() { - return new Category("GS25", CategoryType.STORE); + return new Category("GS25", CategoryType.STORE, "gs25.jpeg"); } public static Category 카테고리_EMART24_생성() { - return new Category("EMART24", CategoryType.STORE); + return new Category("EMART24", CategoryType.STORE, "emart.jpeg"); } public static Category 카테고리_세븐일레븐_생성() { - return new Category("세븐일레븐", CategoryType.STORE); + return new Category("세븐일레븐", CategoryType.STORE, "seven.jpeg"); } } diff --git a/backend/src/test/java/com/funeat/recipe/application/RecipeServiceTest.java b/backend/src/test/java/com/funeat/recipe/application/RecipeServiceTest.java index f68b15d33..1b9b09aba 100644 --- a/backend/src/test/java/com/funeat/recipe/application/RecipeServiceTest.java +++ b/backend/src/test/java/com/funeat/recipe/application/RecipeServiceTest.java @@ -1,28 +1,5 @@ package com.funeat.recipe.application; -import static com.funeat.fixture.CategoryFixture.카테고리_간편식사_생성; -import static com.funeat.fixture.CategoryFixture.카테고리_즉석조리_생성; -import static com.funeat.fixture.ImageFixture.여러_이미지_생성; -import static com.funeat.fixture.MemberFixture.멤버_멤버1_생성; -import static com.funeat.fixture.MemberFixture.멤버_멤버2_생성; -import static com.funeat.fixture.MemberFixture.멤버_멤버3_생성; -import static com.funeat.fixture.PageFixture.페이지요청_생성_시간_내림차순_생성; -import static com.funeat.fixture.PageFixture.페이지요청_생성_시간_오름차순_생성; -import static com.funeat.fixture.PageFixture.페이지요청_좋아요_내림차순_생성; -import static com.funeat.fixture.ProductFixture.레시피_안에_들어가는_상품_생성; -import static com.funeat.fixture.ProductFixture.상품_삼각김밥_가격1000원_평점2점_생성; -import static com.funeat.fixture.ProductFixture.상품_삼각김밥_가격1000원_평점5점_생성; -import static com.funeat.fixture.ProductFixture.상품_삼각김밥_가격2000원_평점1점_생성; -import static com.funeat.fixture.ProductFixture.상품_삼각김밥_가격2000원_평점3점_생성; -import static com.funeat.fixture.ProductFixture.상품_삼각김밥_가격3000원_평점4점_생성; -import static com.funeat.fixture.RecipeFixture.레시피_생성; -import static com.funeat.fixture.RecipeFixture.레시피이미지_생성; -import static com.funeat.fixture.RecipeFixture.레시피좋아요요청_생성; -import static com.funeat.fixture.RecipeFixture.레시피추가요청_생성; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.assertj.core.api.SoftAssertions.assertSoftly; - import com.funeat.common.ServiceTest; import com.funeat.common.dto.PageDto; import com.funeat.member.domain.Member; @@ -38,12 +15,24 @@ import com.funeat.recipe.dto.RecipeDetailResponse; import com.funeat.recipe.dto.RecipeDto; import com.funeat.recipe.exception.RecipeException.RecipeNotFoundException; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; + import java.util.Collections; import java.util.List; import java.util.stream.Collectors; import java.util.stream.Stream; -import org.junit.jupiter.api.Nested; -import org.junit.jupiter.api.Test; + +import static com.funeat.fixture.CategoryFixture.카테고리_간편식사_생성; +import static com.funeat.fixture.CategoryFixture.카테고리_즉석조리_생성; +import static com.funeat.fixture.ImageFixture.여러_이미지_생성; +import static com.funeat.fixture.MemberFixture.*; +import static com.funeat.fixture.PageFixture.*; +import static com.funeat.fixture.ProductFixture.*; +import static com.funeat.fixture.RecipeFixture.*; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.assertj.core.api.SoftAssertions.assertSoftly; @SuppressWarnings("NonAsciiCharacters") class RecipeServiceTest extends ServiceTest { @@ -88,7 +77,7 @@ class create_성공_테스트 { @Test void 레시피의_상세_정보를_조회할_수_있다() { // given - final var category = 카테고리_추가_요청(new Category("간편식사", CategoryType.FOOD)); + final var category = 카테고리_추가_요청(new Category("간편식사", CategoryType.FOOD, "siksa.jpeg")); final var product1 = new Product("불닭볶음면", 1000L, "image.png", "엄청 매운 불닭", category); final var product2 = new Product("참치 삼김", 2000L, "image.png", "담백한 참치마요 삼김", category); final var product3 = new Product("스트링 치즈", 1500L, "image.png", "고소한 치즈", category);