Legend:
- Unmodified
- Added
- Removed
-
src/main/java/com/example/autopartz/service/impl/OrderServiceImpl.java
re02787e r2a552fe 3 3 import com.example.autopartz.model.Client; 4 4 import com.example.autopartz.model.Order; 5 import com.example.autopartz.model.manytomany.OrderContainsPart; 6 import com.example.autopartz.repository.OrderContainsPartRepository; 5 7 import com.example.autopartz.repository.OrderRepository; 6 8 import com.example.autopartz.service.OrderService; 7 9 import org.springframework.stereotype.Service; 8 10 11 import javax.transaction.Transactional; 9 12 import java.util.List; 10 13 @Service 11 14 public class OrderServiceImpl implements OrderService { 12 15 private final OrderRepository orderRepository; 16 private final OrderContainsPartRepository orderContainsPartRepository; 13 17 14 public OrderServiceImpl(OrderRepository orderRepository ) {18 public OrderServiceImpl(OrderRepository orderRepository, OrderContainsPartRepository orderContainsPartRepository) { 15 19 this.orderRepository = orderRepository; 20 this.orderContainsPartRepository = orderContainsPartRepository; 16 21 } 17 22 … … 22 27 23 28 @Override 24 public Order create(Client user) { 25 return orderRepository.save(new Order(user)); 29 @Transactional 30 public Order createOrderAndAddPartToOrder(Client user, Integer partId, Integer quantity) { 31 Order order = orderRepository.save(new Order(user)); 32 orderContainsPartRepository.save(new OrderContainsPart(partId, order.getOrderid(), quantity)); 33 return order; 26 34 } 27 35
Note:
See TracChangeset
for help on using the changeset viewer.