Skip to content

Commit

Permalink
[BE] feat: 카테고리 이미지 추가 (#638)
Browse files Browse the repository at this point in the history
* feat: Category에 image 추가

* feat: CategoryResponse에 image 추가
  • Loading branch information
Go-Jaecheol authored Sep 15, 2023
1 parent 9b413fa commit 3d01ae3
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 45 deletions.
16 changes: 9 additions & 7 deletions backend/src/main/java/com/funeat/product/domain/Category.java
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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() {
Expand All @@ -38,4 +36,8 @@ public String getName() {
public CategoryType getType() {
return type;
}

public String getImage() {
return image;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -23,4 +25,8 @@ public Long getId() {
public String getName() {
return name;
}

public String getImage() {
return image;
}
}
20 changes: 10 additions & 10 deletions backend/src/test/java/com/funeat/fixture/CategoryFixture.java
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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 {
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 3d01ae3

Please sign in to comment.