Java/Spring-app

    주문 검색 기능 개발 // 동적쿼리해결방법

    * 동적쿼리문제 - 주문상태가 Order인것만 보여줘야함 // select * from * where ... - 주문상태가 기본이면 상관없이 다 보여줘야함 // select * from * where X class OrderRepository 해결1 : String 노가다 public List findAllByString(OrderSearch orderSearch) { //language=JPAQL String jpql = "select o From Order o join o.member m"; boolean isFirstCondition = true; //주문 상태 검색 if (orderSearch.getOrderStatus() != null) { if (isFirstCondition) { jpql +..

    주문 기능 테스트 //@Test, Assert

    public class OrderServiceTest { @Autowired EntityManager em; @Autowired OrderService orderService; //오더서비스 받아오기 @Autowired OrderRepository orderRepository; @Test public void 상품주문() throws Exception{ //given Member member=new Member(); member.setName("회원1"); member.setAddress(new Address("서울","경기","123-123")); em.persist(member); Book book= new Book(); book.setName("시골 JPA"); book.setPrice(10000)..

    주문 서비스 개발 // 도메인 모델 패턴, 생성자제한, CASCADE, 변수 수정쿼리

    * 도메인 모델 패턴 엔티티 클래스(Order) : 비즈니스 로직 구현(createOrder 빡구현) 서비스 클래스(OrderService) : 단순히 요청만함.(createOrder) package jpabook.jpashop.domain; import jpabook.jpashop.domain.item.Item; import jpabook.jpashop.repository.ItemRepository; import jpabook.jpashop.repository.MemberRepository; import jpabook.jpashop.repository.OrderRepository; import lombok.RequiredArgsConstructor; import org.springframework.st..

    주문 리포지토리 개발

    package jpabook.jpashop.repository; import jpabook.jpashop.domain.Order; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Repository; import javax.persistence.EntityManager; import java.util.List; @Repository @RequiredArgsConstructor public class OrderRepository { private final EntityManager em; public void save(Order order){ em.persist(order); } public Order findOne(..

    주문, 주문상품 엔티티 개발 // 복잡한생성은 생성메서드

    *생성메서드 class Order //==생성 메서드==// 복잡한생성은 생성메서드로 해결! public static Order createOrder(Member member, Delivery delivery, OrderItem... orderItems){ //...문법 == 유사리스트 Order order = new Order(); order.setMember(member); order.setDelivery(delivery); for(OrderItem orderItem:orderItems){//각각주문에대해 다 add order.addOrderItem(orderItem); } order.setStatus(OrderStatus.ORDER); order.setOrderDate(LocalDateTime.no..

    상품 서비스 개발

    package jpabook.jpashop.service; import jpabook.jpashop.domain.item.Item; import jpabook.jpashop.repository.ItemRepository; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.util.List; @Service @Transactional(readOnly = true) @RequiredArgsConstructor public class ItemService { private..

    상품 리포지토리 개발

    package jpabook.jpashop.repository; import jpabook.jpashop.domain.item.Item; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Repository; import javax.persistence.EntityManager; import java.util.List; @Repository @RequiredArgsConstructor public class ItemRepository { private final EntityManager em; public void save(Item item){ if(item.getId()==null){ em.persist(item);..