Ignore:
Timestamp:
07/26/23 19:26:35 (16 months ago)
Author:
andrejtodorovski <82031894+andrejtodorovski@…>
Branches:
main
Parents:
e02787e
Message:

Added transactional methods to secure the database integrity and refactoring

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/main/java/com/example/autopartz/service/impl/OrderServiceImpl.java

    re02787e r2a552fe  
    33import com.example.autopartz.model.Client;
    44import com.example.autopartz.model.Order;
     5import com.example.autopartz.model.manytomany.OrderContainsPart;
     6import com.example.autopartz.repository.OrderContainsPartRepository;
    57import com.example.autopartz.repository.OrderRepository;
    68import com.example.autopartz.service.OrderService;
    79import org.springframework.stereotype.Service;
    810
     11import javax.transaction.Transactional;
    912import java.util.List;
    1013@Service
    1114public class OrderServiceImpl implements OrderService {
    1215    private final OrderRepository orderRepository;
     16    private final OrderContainsPartRepository orderContainsPartRepository;
    1317
    14     public OrderServiceImpl(OrderRepository orderRepository) {
     18    public OrderServiceImpl(OrderRepository orderRepository, OrderContainsPartRepository orderContainsPartRepository) {
    1519        this.orderRepository = orderRepository;
     20        this.orderContainsPartRepository = orderContainsPartRepository;
    1621    }
    1722
     
    2227
    2328    @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;
    2634    }
    2735
Note: See TracChangeset for help on using the changeset viewer.