Changeset 1bd8d1e


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
Files:
9 added
8 edited

Legend:

Unmodified
Added
Removed
  • src/main/java/com/example/autopartz/config/WebSecurityConfig.java

    r676144b r1bd8d1e  
    2828        http.csrf().disable()
    2929                .authorizeRequests()
    30                 .antMatchers("/", "/products", "/services", "/filtered", "/login", "/register","/registerWarehouseman","/finishRegister","/test/*","/viewUsers","/approve/*").permitAll()
     30                .antMatchers("/", "/products", "/services", "/filtered", "/login", "/register","/registerWarehouseman","/finishRegister","/test/*","/access_denied").permitAll()
    3131                .antMatchers("/orders","/repairs","/reviews","/part/*","/currentOrder").hasRole("CLIENT")
     32                .antMatchers("/viewUsers","/approve/*").hasRole("ADMIN")
    3233                .anyRequest()
    3334                .authenticated()
  • 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")
  • src/main/java/com/example/autopartz/model/Delivery.java

    r676144b r1bd8d1e  
    1818    @Id
    1919    Integer ID_delivery;
    20     String delivery_status;
    21     String delivery_address;
     20    @Column(name = "delivery_status")
     21    String status;
     22    @Column(name = "delivery_address")
     23    String address;
    2224    @ManyToOne
    2325    @JoinColumn(name = "id_user")
  • src/main/java/com/example/autopartz/model/Order.java

    r676144b r1bd8d1e  
    2121    @Id
    2222    @GeneratedValue(strategy = GenerationType.IDENTITY)
    23     Integer ID_order;
     23    @Column(name = "ID_order")
     24    Integer orderid;
    2425    String order_status;
    25     LocalDateTime order_date;
     26    @Column(name = "order_date")
     27    LocalDateTime date;
    2628    @JoinColumn(name = "id_user")
    2729    @ManyToOne
     
    3739        this.order_status = "created";
    3840        this.user = user;
    39         this.order_date = LocalDateTime.now();
     41        this.date = LocalDateTime.now();
    4042    }
    4143
     
    4547        if (o == null || Hibernate.getClass(this) != Hibernate.getClass(o)) return false;
    4648        Order order = (Order) o;
    47         return ID_order != null && Objects.equals(ID_order, order.ID_order);
     49        return orderid != null && Objects.equals(orderid, order.orderid);
    4850    }
    4951
  • src/main/resources/templates/fragments/header.html

    r676144b r1bd8d1e  
    2020            <a class="nav-link active" href="/currentOrder">Моја нарачка</a>
    2121          </li>
     22          </th:block>
     23          <th:block sec:authorize="hasAuthority('ROLE_WAREHOUSEMAN')">
     24            <li class="nav-item m-auto">
     25              <a class="nav-link active" href="/myWarehouse">Мој магацин</a>
     26            </li>
     27          </th:block>
     28          <th:block sec:authorize="hasAuthority('ROLE_DELIVERYMAN')">
     29            <li class="nav-item m-auto">
     30              <a class="nav-link active" href="/myDeliveries">Мои достави</a>
     31            </li>
     32          </th:block>
     33          <th:block sec:authorize="hasAuthority('ROLE_ADMIN')">
     34            <li class="nav-item m-auto">
     35              <a class="nav-link active" href="/viewUsers">Корисници</a>
     36            </li>
    2237          </th:block>
    2338        </ul>
Note: See TracChangeset for help on using the changeset viewer.