Ignore:
Timestamp:
01/05/23 12:40:07 (23 months ago)
Author:
andrejtodorovski <82031894+andrejtodorovski@…>
Branches:
main
Children:
f484b14
Parents:
676144b
Message:

Added views and functionalities for deliveryman, warehouseman and admin

Location:
src/main/java/com/example/autopartz/controller
Files:
4 edited

Legend:

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

    r676144b r1bd8d1e  
    1313import org.springframework.web.bind.annotation.RequestMapping;
    1414
     15import javax.annotation.security.RolesAllowed;
    1516import javax.servlet.http.HttpServletResponse;
    1617import java.io.IOException;
  • src/main/java/com/example/autopartz/controller/HomeController.java

    r676144b r1bd8d1e  
    11package com.example.autopartz.controller;
    22
    3 import com.example.autopartz.model.Order;
    4 import com.example.autopartz.model.User;
    5 import com.example.autopartz.model.Warehouse;
    6 import com.example.autopartz.repository.OrderContainsPartRepository;
    7 import com.example.autopartz.repository.PartsForCarTypeAndCategoryRepository;
    8 import com.example.autopartz.repository.RepairShopReviewSummaryRepository;
    9 import com.example.autopartz.repository.WarehouseRepository;
     3import com.example.autopartz.model.*;
     4import com.example.autopartz.model.manytomany.PartIsInStockInWarehouse;
     5import com.example.autopartz.repository.*;
    106import com.example.autopartz.service.*;
    117import org.springframework.stereotype.Controller;
     
    2016import javax.servlet.http.HttpSession;
    2117import java.io.IOException;
     18import java.util.List;
    2219import java.util.Objects;
    2320
     
    3431    private final OrderContainsPartRepository orderContainsPartRepository;
    3532    private final OrderService orderService;
    36 
     33    private final UserService userService;
     34    private final DeliveryService deliveryService;
     35    private final PartIsInStockInWarehouseRepository partIsInStockInWarehouseRepository;
    3736    public HomeController(LoginService loginService, PartService partService, PartsForCarTypeAndCategoryRepository partsForCarTypeAndCategoryRepository, CarService carService, CategoryService categoryService, RepairShopReviewSummaryRepository repairShopReviewSummaryRepository, WarehouseRepository warehouseRepository,
    38                           OrderContainsPartRepository orderContainsPartRepository, OrderService orderService) {
     37                          OrderContainsPartRepository orderContainsPartRepository, OrderService orderService, UserService userService, DeliveryService deliveryService, PartIsInStockInWarehouseRepository partIsInStockInWarehouseRepository) {
    3938        this.loginService = loginService;
    4039        this.partService = partService;
     
    4645        this.orderContainsPartRepository = orderContainsPartRepository;
    4746        this.orderService = orderService;
     47        this.userService = userService;
     48        this.deliveryService = deliveryService;
     49        this.partIsInStockInWarehouseRepository = partIsInStockInWarehouseRepository;
    4850    }
    4951
     
    7880            model.addAttribute("hasError",false);
    7981            model.addAttribute("order",o);
    80             model.addAttribute("parts",orderService.findById(o.getID_order()).getPartList());
     82            model.addAttribute("parts",orderService.findById(o.getOrderid()).getPartList());
    8183        }
    8284        model.addAttribute("bodyContent","currentOrder");
     
    154156        }
    155157    }
     158    @GetMapping("/access_denied")
     159    public String accessDenied(Model model){
     160        model.addAttribute("bodyContent","access_denied");
     161        return "master-template";
     162    }
     163    @GetMapping("/myWarehouse")
     164    public String myWarehouse(Model model, HttpServletRequest request){
     165        Warehouseman whm = (Warehouseman) userService.findByUsername(request.getRemoteUser());
     166        Warehouse warehouse = whm.getWarehouse();
     167        List<PartIsInStockInWarehouse> partIsInStockInWarehouseList = partIsInStockInWarehouseRepository.findAllByWarehouseid(warehouse.getID_warehouse());
     168        model.addAttribute("bodyContent","myWarehouse");
     169        model.addAttribute("warehouse",warehouse);
     170        model.addAttribute("parts", partIsInStockInWarehouseList);
     171        return "master-template";
     172    }
     173    @GetMapping("myDeliveries")
     174    public String myDeliveries(Model model, HttpServletRequest request){
     175        Deliveryman dm = (Deliveryman) userService.findByUsername(request.getRemoteUser());
     176        List<Delivery> deliveries = deliveryService.findAllByDeliverer(dm);
     177        model.addAttribute("bodyContent","myDeliveries");
     178        model.addAttribute("deliveries",deliveries);
     179        return "master-template";
     180    }
    156181}
  • src/main/java/com/example/autopartz/controller/PartController.java

    r676144b r1bd8d1e  
    7777        }
    7878        Order order = (Order) session.getAttribute("order");
    79         orderContainsPartRepository.save(new OrderContainsPart(id,order.getID_order(),quantity));
     79        orderContainsPartRepository.save(new OrderContainsPart(id,order.getOrderid(),quantity));
    8080        try {
    8181            response.sendRedirect("/products");
  • src/main/java/com/example/autopartz/controller/TestController.java

    r676144b r1bd8d1e  
    3636        User u = userService.findByUsername("client13");
    3737        Order o = orderService.create((Client) u);
    38         orderContainsPartRepository.save(new OrderContainsPart(5,o.getID_order(),2));
    39         orderContainsPartRepository.save(new OrderContainsPart(7,o.getID_order(),1));
     38        orderContainsPartRepository.save(new OrderContainsPart(5,o.getOrderid(),2));
     39        orderContainsPartRepository.save(new OrderContainsPart(7,o.getOrderid(),1));
    4040    }
    4141    @GetMapping("/t")
Note: See TracChangeset for help on using the changeset viewer.