forked from codesquad-members-2022/sidedish
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat: 특정 Products의 meal type 조회 기능의 리포지토리 구현
- 테스트 작성 Co-authored-by: “Louie-03” <dhdustnr0134@naver.com>
- Loading branch information
Showing
9 changed files
with
139 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,20 @@ | ||
package sidedish.com.domain; | ||
|
||
import lombok.Getter; | ||
import lombok.ToString; | ||
import org.springframework.data.annotation.Id; | ||
import org.springframework.data.relational.core.mapping.Table; | ||
|
||
@Getter | ||
@Table("PRODUCT_IMAGE") | ||
@ToString | ||
public class Image { | ||
|
||
private String image; | ||
@Id | ||
private Long id; | ||
private String imageUrl; | ||
|
||
public Image(String image) { | ||
this.image = image; | ||
public Image(String imageUrl) { | ||
this.imageUrl = imageUrl; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 7 additions & 2 deletions
9
BE/src/main/java/sidedish/com/repository/ProductsRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,16 @@ | ||
package sidedish.com.repository; | ||
|
||
import java.util.List; | ||
import org.springframework.data.jdbc.repository.query.Query; | ||
import org.springframework.data.repository.CrudRepository; | ||
import org.springframework.data.repository.query.Param; | ||
import org.springframework.stereotype.Repository; | ||
import sidedish.com.domain.Product; | ||
|
||
@Repository | ||
public interface ProductsRepository { | ||
public interface ProductsRepository extends CrudRepository<Product, Long> { | ||
|
||
List<Product> findByMealType(String meal); | ||
@Query("select id, discount_policy_id, product_name, description, original_price, meal_category " | ||
+ "from product where meal_category = :mealType") | ||
List<Product> findByMealType(@Param("mealType") String mealType); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
BE/src/test/java/sidedish/com/repository/ProductsRepositoryTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package sidedish.com.repository; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import java.util.List; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Nested; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.autoconfigure.data.jdbc.DataJdbcTest; | ||
import org.springframework.test.context.jdbc.Sql; | ||
import org.springframework.test.context.junit.jupiter.SpringExtension; | ||
import sidedish.com.domain.Product; | ||
|
||
@DataJdbcTest | ||
@DisplayName("ProductsRepository 클래스") | ||
class ProductsRepositoryTest { | ||
|
||
@Autowired | ||
private ProductsRepository productsRepository; | ||
|
||
@BeforeEach | ||
@Sql({"/testdb/schema.sql", "/testdb/data.sql"}) | ||
void setUp() { | ||
|
||
} | ||
|
||
@Nested | ||
@DisplayName("findByMealType(String meal) 메서드") | ||
class Describe_findByMealType { | ||
|
||
@Nested | ||
@DisplayName("만약 meal 타입이 유효한 soup으로 주어진다면") | ||
class Context_with_meal_type_is_soup { | ||
|
||
@Test | ||
@DisplayName("meal 타입이 soup인 모든 Product의 리스트를 반환한다") | ||
void It_returns_products_type_soup() { | ||
List<Product> result = productsRepository.findByMealType("soup"); | ||
|
||
assertThat(result.get(0).getMealCategory()).isEqualTo("soup"); | ||
} | ||
} | ||
|
||
@Nested | ||
@DisplayName("만약 meal이 유효한 main으로 주어진다면") | ||
class Context_with_meal_type_is_main { | ||
|
||
@Test | ||
@DisplayName("meal 타입이 main인 모든 Product의 리스트를 반환한다") | ||
void It_returns_products_type_main() { | ||
List<Product> result = productsRepository.findByMealType("main"); | ||
|
||
assertThat(result.get(0).getMealCategory()).isEqualTo("main"); | ||
} | ||
} | ||
|
||
@Nested | ||
@DisplayName("만약 meal이 유효한 side으로 주어진다면") | ||
class Context_with_meal_type_is_side { | ||
|
||
@Test | ||
@DisplayName("meal 타입이 side인 모든 Product의 리스트를 반환한다") | ||
void It_returns_products_type_side() { | ||
List<Product> result = productsRepository.findByMealType("side"); | ||
|
||
assertThat(result.get(0).getMealCategory()).isEqualTo("side"); | ||
} | ||
} | ||
|
||
@Nested | ||
@DisplayName("만약 meal이 유효하지 않은 값으로 주어진다면") | ||
class Context_with_meal_type_error { | ||
|
||
@Test | ||
@DisplayName("빈 리스트를 반환한다.") | ||
void It_returns_products_type_side() { | ||
List<Product> result = productsRepository.findByMealType("error Meal Type"); | ||
|
||
assertThat(result).isEmpty(); | ||
} | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters