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/HomeController.java

    re02787e r2a552fe  
    11package com.example.autopartz.controller;
    22
    3 import com.example.autopartz.model.*;
    43import com.example.autopartz.model.DTO.CurrentOrderDTO;
    54import com.example.autopartz.model.DTO.OrderInfo;
     5import com.example.autopartz.model.*;
    66import com.example.autopartz.model.manytomany.OrderContainsPart;
    77import com.example.autopartz.model.manytomany.PartIsInStockInWarehouse;
    8 import com.example.autopartz.model.manytomany.PartIsInStockInWarehouseId;
    98import com.example.autopartz.model.views.DeliveriesInProgress;
    109import com.example.autopartz.model.views.PartsForCarTypeAndCategory;
     
    2019import java.io.IOException;
    2120import java.util.ArrayList;
    22 import java.util.Comparator;
    2321import java.util.List;
    2422import java.util.Objects;
     
    103101            int total = 0;
    104102            List<OrderContainsPart> qList = orderContainsPartRepository.findAllByOrderid(o.getOrderid());
    105             for (int i = 0; i < qList.size(); i++) {
    106                 int pr = qList.get(i).getQuantity_order()*
    107                         priceService.findPriceForPart(partService.findById(qList.get(i).getPartid())).stream().findFirst().get().getAmount();
     103            for (OrderContainsPart orderContainsPart : qList) {
     104                int pr = orderContainsPart.getQuantity_order() *
     105                        priceService.findPriceForPart(partService.findById(orderContainsPart.getPartid())).stream().findFirst().get().getAmount();
    108106                CurrentOrderDTO temp = new CurrentOrderDTO(
    109                         partService.findById(qList.get(i).getPartid()).getName(),
    110                         partService.findById(qList.get(i).getPartid()).getManufacturer().getName(),
    111                         qList.get(i).getQuantity_order(),
     107                        partService.findById(orderContainsPart.getPartid()).getName(),
     108                        partService.findById(orderContainsPart.getPartid()).getManufacturer().getName(),
     109                        orderContainsPart.getQuantity_order(),
    112110                        pr);
    113111                list.add(temp);
    114                 total+=pr;
     112                total += pr;
    115113            }
    116114            model.addAttribute("total",total);
     
    188186    }
    189187    @PostMapping("/finishRegister")
    190     public void handleWarehousemanRegister(@RequestParam String location,Model model, HttpServletResponse response, HttpSession session){
     188    public void handleWarehousemanRegister(@RequestParam String location, HttpServletResponse response, HttpSession session){
    191189        System.out.println("here?");
    192190        String username = (String) session.getAttribute("username");
     
    243241    }
    244242    @PostMapping("/finishDelivery/{id}")
    245     public void finishDelivery(@PathVariable Integer id, Model model, HttpServletResponse response){
     243    public void finishDelivery(@PathVariable Integer id, HttpServletResponse response){
    246244        Delivery d = deliveryService.findByOrder(orderService.findById(id));
    247245        d.setStatus("finished");
     
    257255        List<OrderContainsPart> list = orderContainsPartRepository.findAllByOrderid(id);
    258256        List<OrderInfo> partList = new ArrayList<>();
    259         for (int i = 0; i < list.size(); i++) {
    260             OrderInfo oi = new OrderInfo(partService.findById(list.get(i).getPartid()).getName(),
    261                     list.get(i).getQuantity_order(),partService.findById(list.get(i).getPartid()).getManufacturer().getName());
     257        for (OrderContainsPart orderContainsPart : list) {
     258            OrderInfo oi = new OrderInfo(partService.findById(orderContainsPart.getPartid()).getName(),
     259                    orderContainsPart.getQuantity_order(), partService.findById(orderContainsPart.getPartid()).getManufacturer().getName());
    262260            partList.add(oi);
    263261        }
     
    301299        Warehouse wh = whm.getWarehouse();
    302300        Integer whId = wh.getId();
    303         PartIsInStockInWarehouseId tmp = new PartIsInStockInWarehouseId(pId,whId);
    304         PartIsInStockInWarehouse temp = partIsInStockInWarehouseRepository.findById(tmp).get();
    305         temp.setQuantity(temp.getQuantity()+quantity);
    306         partIsInStockInWarehouseRepository.save(temp);
     301        partService.addPartToWarehouse(pId,quantity,whId);
    307302        try {
    308303            response.sendRedirect("/myWarehouseReport");
Note: See TracChangeset for help on using the changeset viewer.