[ SourceCode 참고]

https://github.com/jjangsky/Testing-study

요구 사항

키오스크 주문을 위한 상품 후보 리스트 조회하기

상품의 판매 상태 : 판매중, 판매보류, 판매중지

id, 상품번호, 상품 타입, 판매 상태, 상품 이름, 가격

Entity 설정

Untitled

요구사항에 맞춰 상품의 조회, 주문, 수정을 하기 위한 Entity를 설정할 수 있다.

원래 같으면 Order Entity와 Prodcut Entity 두 개를 가지고 설정할 수 있지만 Entity 사이의 연관관계에 의해서 하나의 MappingTable을 만들어 해소 시킬 수 있다.

Production Code

@Repository
public interface ProductRepository extends JpaRepository<Product, Long> {
    /**
     * select *
     * from product
     * where selling_type in ('SELLING', 'HOLD')
     */
    List<Product> findAllBySellingStatusIn(List<ProductSellingStatus> sellingStatuses);
} 

Persistence 계층은 DB와 가장 밀접한 계층으로 데이터의 CRUD 작업만 이루어지는 계층이다.

JPA의 메소드 네이밍을 이용하여 단순하게 조건문에 대한 쿼리 조회를 실행하는 메소드이다.