Ignore:
Timestamp:
01/07/23 01:51:16 (23 months ago)
Author:
andrejtodorovski <82031894+andrejtodorovski@…>
Branches:
main
Children:
ed7ef92
Parents:
89865ae
Message:

Final touches

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/main/java/com/example/autopartz/controller/HomeController.java

    r89865ae r4d67d70  
    66import com.example.autopartz.model.manytomany.OrderContainsPart;
    77import com.example.autopartz.model.manytomany.PartIsInStockInWarehouse;
     8import com.example.autopartz.model.manytomany.PartIsInStockInWarehouseId;
    89import com.example.autopartz.model.views.DeliveriesInProgress;
    910import com.example.autopartz.model.views.PartsForCarTypeAndCategory;
     
    4243    private final MostPurchasedPartRepository mostPurchasedPartRepository;
    4344    private final PriceService priceService;
     45    private final WarehousemanReportRepository warehousemanReportRepository;
     46    private final PartRepository partRepository;
    4447    public HomeController(LoginService loginService, PartService partService, PartsForCarTypeAndCategoryRepository partsForCarTypeAndCategoryRepository, CarService carService, CategoryService categoryService, RepairShopReviewSummaryRepository repairShopReviewSummaryRepository, WarehouseRepository warehouseRepository,
    45                           OrderContainsPartRepository orderContainsPartRepository, OrderService orderService, UserService userService, DeliveriesInProgressRepository deliveriesInProgressRepository, DeliveryService deliveryService, PartIsInStockInWarehouseRepository partIsInStockInWarehouseRepository, CarCategoryReportRepository carCategoryReportRepository, PartManufacturersReportRepository partManufacturersReportRepository, MostPurchasedPartRepository mostPurchasedPartRepository, PriceService priceService) {
     48                          OrderContainsPartRepository orderContainsPartRepository, OrderService orderService, UserService userService, DeliveriesInProgressRepository deliveriesInProgressRepository, DeliveryService deliveryService, PartIsInStockInWarehouseRepository partIsInStockInWarehouseRepository, CarCategoryReportRepository carCategoryReportRepository, PartManufacturersReportRepository partManufacturersReportRepository, MostPurchasedPartRepository mostPurchasedPartRepository, PriceService priceService, WarehousemanReportRepository warehousemanReportRepository, PartRepository partRepository) {
    4649        this.loginService = loginService;
    4750        this.partService = partService;
     
    6164        this.mostPurchasedPartRepository = mostPurchasedPartRepository;
    6265        this.priceService = priceService;
     66        this.warehousemanReportRepository = warehousemanReportRepository;
     67        this.partRepository = partRepository;
    6368    }
    6469
     
    201206        Warehouseman whm = (Warehouseman) userService.findByUsername(request.getRemoteUser());
    202207        Warehouse warehouse = whm.getWarehouse();
    203         List<PartIsInStockInWarehouse> partIsInStockInWarehouseList = partIsInStockInWarehouseRepository.findAllByWarehouseid(warehouse.getID_warehouse());
     208        List<PartIsInStockInWarehouse> partIsInStockInWarehouseList = partIsInStockInWarehouseRepository.findAllByWarehouseid(warehouse.getId());
    204209        model.addAttribute("bodyContent","myWarehouse");
    205210        model.addAttribute("warehouse",warehouse);
     
    274279        return "master-template";
    275280    }
     281    @GetMapping("/myWarehouseReport")
     282    public String getMyWarehouseReport(Model model, HttpServletRequest request){
     283        Warehouseman whm = (Warehouseman) userService.findByUsername(request.getRemoteUser());
     284        Warehouse wh = whm.getWarehouse();
     285        Integer whId = wh.getId();
     286        model.addAttribute("data", warehousemanReportRepository.findByWid(whId));
     287        model.addAttribute("bodyContent","myWarehouseReport");
     288        return "master-template";
     289    }
     290    @PostMapping("/myWarehouse/{pname}")
     291    public void addPartToWarehouse(@PathVariable String pname,@RequestParam Integer quantity, HttpServletRequest request, HttpServletResponse response){
     292        Integer pId = partRepository.findAllByName(pname).stream().findFirst().get().getId();
     293        Warehouseman whm = (Warehouseman) userService.findByUsername(request.getRemoteUser());
     294        Warehouse wh = whm.getWarehouse();
     295        Integer whId = wh.getId();
     296        PartIsInStockInWarehouseId tmp = new PartIsInStockInWarehouseId(pId,whId);
     297        PartIsInStockInWarehouse temp = partIsInStockInWarehouseRepository.findById(tmp).get();
     298        temp.setQuantity(temp.getQuantity()+quantity);
     299        partIsInStockInWarehouseRepository.save(temp);
     300        try {
     301            response.sendRedirect("/myWarehouseReport");
     302        } catch (IOException e) {
     303            throw new RuntimeException(e);
     304        }
     305    }
    276306}
Note: See TracChangeset for help on using the changeset viewer.