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/controller/PartController.java

    re02787e r2a552fe  
    7171    }
    7272    @PostMapping("/repairshopdelivery")
    73     public void setRepairShopDelivery(@RequestParam Integer vin, HttpServletResponse response, HttpSession session, HttpServletRequest request){
     73    public void setRepairShopDelivery(@RequestParam Integer vin, HttpServletResponse response, HttpSession session){
    7474        // insert into project.repair (vin, id_repair_shop, id_service_book) values (1111,3,1)
    7575        session.setAttribute("carVin",vin);
     
    107107        RepairShop repairShop = repairShopService.getById(rs);
    108108        repairRepository.save(new Repair(o,repairShop,sb));
    109 //        o.setOrder_status("finished");
    110 //        orderService.save(o);
    111109        session.removeAttribute("order");
    112110        try {
     
    125123        Deliveryman dm = deliverymanList.get(deliverer);
    126124        deliveryRepository.save(new Delivery("in progress",address,dm,o));
    127 //        o.setOrder_status("finished");
    128 //        orderService.save(o);
    129125        session.removeAttribute("order");
    130126        try {
     
    138134        if(session.getAttribute("order")==null){
    139135            User u = userService.findByUsername(request.getRemoteUser());
    140             Order newOrder = orderService.create((Client) u);
     136            Order newOrder = orderService.createOrderAndAddPartToOrder((Client) u, id, quantity);
    141137            session.setAttribute("order",newOrder);
     138        } else {
     139            Order order = (Order) session.getAttribute("order");
     140            orderContainsPartRepository.save(new OrderContainsPart(id, order.getOrderid(), quantity));
    142141        }
    143         Order order = (Order) session.getAttribute("order");
    144         orderContainsPartRepository.save(new OrderContainsPart(id,order.getOrderid(),quantity));
    145142        try {
    146143            response.sendRedirect("/products");
Note: See TracChangeset for help on using the changeset viewer.