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

[BE] feat: 카테고리 이미지 추가 #638

Merged
merged 2 commits into from
Sep 15, 2023
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
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