Changeset 4d67d70


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

Final touches

Location:
src/main
Files:
12 added
19 edited

Legend:

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

    r89865ae r4d67d70  
    3030                .antMatchers("/", "/products", "/services", "/filtered", "/login", "/register","/registerWarehouseman","/finishRegister","/test/*","/access_denied","/carCategoryReport","/partManufacturersReport","/mostPurchasedPart").permitAll()
    3131                .antMatchers("/orders","/repairs","/reviews","/part/*","/currentOrder","/addCarSampleForUser","/repairs/addReview/*").hasRole("CLIENT")
    32                 .antMatchers("/viewUsers","/approve/*").hasRole("ADMIN")
     32                .antMatchers("/viewUsers","/approve/*","/addPart").hasRole("ADMIN")
     33                .antMatchers("/myWarehouseReport","myWarehouse").hasRole("WAREHOUSEMAN")
    3334                .anyRequest()
    3435                .authenticated()
  • src/main/java/com/example/autopartz/controller/AdminController.java

    r89865ae r4d67d70  
    11package com.example.autopartz.controller;
    22
    3 import com.example.autopartz.model.Deliveryman;
    4 import com.example.autopartz.model.Role;
    5 import com.example.autopartz.model.User;
    6 import com.example.autopartz.model.Warehouseman;
    7 import com.example.autopartz.repository.DeliverymanRepository;
    8 import com.example.autopartz.repository.WarehousemanRepository;
     3import com.example.autopartz.model.*;
     4import com.example.autopartz.model.manytomany.PartIsAppropriateForCar;
     5import com.example.autopartz.model.manytomany.PartIsFromCategory;
     6import com.example.autopartz.model.manytomany.PartIsInStockInWarehouse;
     7import com.example.autopartz.repository.*;
     8import com.example.autopartz.service.PriceService;
    99import com.example.autopartz.service.UserService;
    1010import org.springframework.stereotype.Controller;
    1111import org.springframework.ui.Model;
    12 import org.springframework.web.bind.annotation.GetMapping;
    13 import org.springframework.web.bind.annotation.PathVariable;
    14 import org.springframework.web.bind.annotation.PostMapping;
    15 import org.springframework.web.bind.annotation.RequestMapping;
     12import org.springframework.web.bind.annotation.*;
    1613
    1714import javax.servlet.http.HttpServletResponse;
    1815import java.io.IOException;
    1916import java.time.LocalDate;
     17import java.time.LocalDateTime;
    2018import java.util.List;
    2119import java.util.Objects;
     
    2523public class AdminController {
    2624    private final UserService userService;
     25    private final PartIsFromCategoryRepository partIsFromCategoryRepository;
     26    private final PartIsAppropriateForCarRepository partIsAppropriateForCarRepository;
    2727    private final WarehousemanRepository warehousemanRepository;
     28    private final PartIsInStockInWarehouseRepository partIsInStockInWarehouseRepository;
    2829    private final DeliverymanRepository deliverymanRepository;
     30    private final CategoryRepository categoryRepository;
     31    private final PartRepository partRepository;
     32    private final WarehouseRepository warehouseRepository;
     33    private final CarRepository carRepository;
     34    private final PartManufacturerRepository partManufacturerRepository;
     35    private final PriceService priceService;
    2936
    30     public AdminController(UserService userService, WarehousemanRepository warehousemanRepository, DeliverymanRepository deliverymanRepository) {
     37    public AdminController(UserService userService, PartIsFromCategoryRepository partIsFromCategoryRepository, PartIsAppropriateForCarRepository partIsAppropriateForCarRepository, WarehousemanRepository warehousemanRepository, PartIsInStockInWarehouseRepository partIsInStockInWarehouseRepository, DeliverymanRepository deliverymanRepository, CategoryRepository categoryRepository, PartRepository partRepository, WarehouseRepository warehouseRepository, CarRepository carRepository, PartManufacturerRepository partManufacturerRepository, PriceService priceService) {
    3138        this.userService = userService;
     39        this.partIsFromCategoryRepository = partIsFromCategoryRepository;
     40        this.partIsAppropriateForCarRepository = partIsAppropriateForCarRepository;
    3241        this.warehousemanRepository = warehousemanRepository;
     42        this.partIsInStockInWarehouseRepository = partIsInStockInWarehouseRepository;
    3343        this.deliverymanRepository = deliverymanRepository;
     44        this.categoryRepository = categoryRepository;
     45        this.partRepository = partRepository;
     46        this.warehouseRepository = warehouseRepository;
     47        this.carRepository = carRepository;
     48        this.partManufacturerRepository = partManufacturerRepository;
     49        this.priceService = priceService;
    3450    }
    3551
     
    6682        }
    6783    }
     84    @GetMapping("/addPart")
     85    public String addPart(Model model){
     86        model.addAttribute("categories",categoryRepository.findAll());
     87        model.addAttribute("warehouses",warehouseRepository.findAll());
     88        model.addAttribute("cars",carRepository.findAll());
     89        model.addAttribute("manufacturers",partManufacturerRepository.findAll());
     90        model.addAttribute("bodyContent","addPart");
     91        return "master-template";
     92    }
     93    @PostMapping("/addPart")
     94    public void addPart(@RequestParam String name, @RequestParam(required = false) String description,
     95                        @RequestParam Integer manufacturer, @RequestParam List<Car> cars,
     96                        @RequestParam List<Category> categories, @RequestParam Integer warehouse,
     97                        @RequestParam Integer quantity, @RequestParam Integer amount, HttpServletResponse response){
     98        // Part(String name, String description, PartManufacturer manufacturer, List<Category> categoryList, List<Warehouse> warehouseList, List<Car> carList) {
     99        Part newPart = new Part(name, description==null ? "" : description, partManufacturerRepository.findById(manufacturer).get(),
     100                categories, List.of(warehouseRepository.findById(warehouse).get()),cars);
     101        partRepository.save(newPart);
     102        priceService.save(new Price(amount, LocalDate.now(),newPart));
     103        partIsInStockInWarehouseRepository.save(new PartIsInStockInWarehouse(newPart.getId(),warehouse,quantity));
     104        for (Category c:categories
     105             ) {
     106            partIsFromCategoryRepository.save(new PartIsFromCategory(newPart.getId(),c.getId()));
     107        }
     108        for (Car car:cars){
     109            partIsAppropriateForCarRepository.save(new PartIsAppropriateForCar(newPart.getId(),car.getId()));
     110        }
     111        try {
     112            response.sendRedirect("/");
     113        } catch (IOException e) {
     114            throw new RuntimeException(e);
     115        }
     116    }
    68117}
  • 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}
  • src/main/java/com/example/autopartz/model/Category.java

    r89865ae r4d67d70  
    1717public class Category {
    1818    @Id
    19     Integer ID_category;
     19    @Column(name = "id_category")
     20    Integer id;
    2021    @Column(name = "category_name")
    2122    String cname;
     
    2930        if (o == null || Hibernate.getClass(this) != Hibernate.getClass(o)) return false;
    3031        Category category = (Category) o;
    31         return ID_category != null && Objects.equals(ID_category, category.ID_category);
     32        return id != null && Objects.equals(id, category.id);
    3233    }
    3334
  • src/main/java/com/example/autopartz/model/Part.java

    r89865ae r4d67d70  
    1818public class Part {
    1919    @Id
     20    @GeneratedValue(strategy = GenerationType.IDENTITY)
    2021    @Column(name = "ID_part")
    2122    Integer id;
     
    4647    List<Car> carList;
    4748
     49    public Part(String name, String description, PartManufacturer manufacturer, List<Category> categoryList, List<Warehouse> warehouseList, List<Car> carList) {
     50        this.name = name;
     51        this.description = description;
     52        this.manufacturer = manufacturer;
     53        this.categoryList = categoryList;
     54        this.warehouseList = warehouseList;
     55        this.carList = carList;
     56    }
     57
    4858    @Override
    4959    public boolean equals(Object o) {
  • src/main/java/com/example/autopartz/model/PartManufacturer.java

    r89865ae r4d67d70  
    2121public class PartManufacturer {
    2222    @Id
    23     Integer ID_part_manufacturer;
     23    @Column(name = "id_part_manufacturer")
     24    Integer id;
    2425    @Column(name = "pm_name")
    2526    String name;
     
    3132        if (o == null || Hibernate.getClass(this) != Hibernate.getClass(o)) return false;
    3233        PartManufacturer that = (PartManufacturer) o;
    33         return ID_part_manufacturer != null && Objects.equals(ID_part_manufacturer, that.ID_part_manufacturer);
     34        return id != null && Objects.equals(id, that.id);
    3435    }
    3536
  • src/main/java/com/example/autopartz/model/Price.java

    r89865ae r4d67d70  
    77import org.hibernate.Hibernate;
    88
    9 import javax.persistence.Entity;
    10 import javax.persistence.Id;
    11 import javax.persistence.JoinColumn;
    12 import javax.persistence.ManyToOne;
     9import javax.persistence.*;
    1310import java.time.LocalDate;
    1411import java.util.Objects;
     
    2118public class Price {
    2219    @Id
     20    @GeneratedValue(strategy = GenerationType.IDENTITY)
    2321    Integer ID_price;
    2422    Integer amount;
     
    2826    @JoinColumn(name = "id_part")
    2927    Part part;
     28
     29    public Price(Integer amount, LocalDate price_from, Part part) {
     30        this.amount = amount;
     31        this.price_from = price_from;
     32        this.part = part;
     33    }
    3034
    3135    @Override
  • src/main/java/com/example/autopartz/model/Warehouse.java

    r89865ae r4d67d70  
    1919public class Warehouse {
    2020    @Id
    21     Integer ID_warehouse;
     21    @Column(name = "id_warehouse")
     22    Integer id;
    2223    @Column(name = "warehouse_location")
    2324    String location;
     
    2829        if (o == null || Hibernate.getClass(this) != Hibernate.getClass(o)) return false;
    2930        Warehouse warehouse = (Warehouse) o;
    30         return ID_warehouse != null && Objects.equals(ID_warehouse, warehouse.ID_warehouse);
     31        return id != null && Objects.equals(id, warehouse.id);
    3132    }
    3233
  • src/main/java/com/example/autopartz/model/manytomany/PartIsInStockInWarehouse.java

    r89865ae r4d67d70  
    11package com.example.autopartz.model.manytomany;
    22
    3 import lombok.Getter;
    4 import lombok.RequiredArgsConstructor;
    5 import lombok.Setter;
    6 import lombok.ToString;
     3import lombok.*;
    74
    85import javax.persistence.*;
     
    129@Setter
    1310@ToString
    14 @RequiredArgsConstructor
     11@NoArgsConstructor
    1512@Table(name = "`part_is_in_stock_in_warehouse`")
    1613@IdClass(PartIsInStockInWarehouseId.class)
     
    2421    @Column(name = "quantity_warehouse")
    2522    Integer quantity;
     23
     24    public PartIsInStockInWarehouse(Integer partid, Integer warehouseid, Integer quantity) {
     25        this.partid = partid;
     26        this.warehouseid = warehouseid;
     27        this.quantity = quantity;
     28    }
    2629}
  • src/main/java/com/example/autopartz/model/manytomany/PartIsInStockInWarehouseId.java

    r89865ae r4d67d70  
    99    Integer partid;
    1010    Integer warehouseid;
     11
     12    public PartIsInStockInWarehouseId(Integer pId, Integer whId) {
     13        this.partid = pId;
     14        this.warehouseid = whId;
     15    }
     16
     17    public PartIsInStockInWarehouseId() {
     18    }
    1119}
  • src/main/java/com/example/autopartz/repository/PartRepository.java

    r89865ae r4d67d70  
    55import org.springframework.stereotype.Repository;
    66
     7import java.util.List;
     8
    79@Repository
    810public interface PartRepository extends JpaRepository<Part,Integer> {
     11    List<Part> findAllByName(String name);
    912}
  • src/main/java/com/example/autopartz/repository/WarehouseRepository.java

    r89865ae r4d67d70  
    88public interface WarehouseRepository extends JpaRepository<Warehouse,Integer> {
    99    List<Warehouse> findAllByLocation(String location);
     10    List<Warehouse> findAllById(Integer id);
    1011}
  • src/main/java/com/example/autopartz/repository/WarehousemanRepository.java

    r89865ae r4d67d70  
    11package com.example.autopartz.repository;
    22
     3import com.example.autopartz.model.Warehouse;
    34import com.example.autopartz.model.Warehouseman;
    45import org.springframework.data.jpa.repository.JpaRepository;
    56
     7import java.util.List;
     8
    69public interface WarehousemanRepository extends JpaRepository<Warehouseman,Integer> {
     10    List<Warehouseman> findAllByWarehouse(Warehouse warehouse);
    711}
  • src/main/java/com/example/autopartz/service/PriceService.java

    r89865ae r4d67d70  
    88public interface PriceService {
    99    List<Price> findPriceForPart(Part part);
     10    void save(Price p);
    1011}
  • src/main/java/com/example/autopartz/service/impl/PriceServiceImpl.java

    r89865ae r4d67d70  
    2222        return priceRepository.findAllByPart(part);
    2323    }
     24
     25    @Override
     26    public void save(Price p) {
     27        priceRepository.save(p);
     28    }
    2429}
  • src/main/resources/templates/carCategoryReport.html

    r89865ae r4d67d70  
    1111    <tbody>
    1212    <tr th:each="d : ${data}">
    13       <td th:text="${d.getCname}"></td>
     13      <td th:text="${d.getCname()}"></td>
    1414      <td th:text="${d.getCmname()}"></td>
    1515      <td th:text="${d.getPartsordered()}"></td>
  • src/main/resources/templates/fragments/header.html

    r89865ae r4d67d70  
    4040            </li>
    4141          </th:block>
     42          <th:block sec:authorize="hasAuthority('ROLE_WAREHOUSEMAN')">
     43            <li class="nav-item m-auto">
     44              <a class="nav-link active" href="/myWarehouseReport">Информации за потреби</a>
     45            </li>
     46          </th:block>
    4247          <th:block sec:authorize="hasAuthority('ROLE_DELIVERYMAN')">
    4348            <li class="nav-item m-auto">
     
    4853            <li class="nav-item m-auto">
    4954              <a class="nav-link active" href="/viewUsers">Корисници</a>
     55            </li>
     56          </th:block>
     57          <th:block sec:authorize="hasAuthority('ROLE_ADMIN')">
     58            <li class="nav-item m-auto">
     59              <a class="nav-link active" href="/addPart">Додај дел во системот</a>
    5060            </li>
    5161          </th:block>
  • src/main/resources/templates/myDeliveries.html

    r89865ae r4d67d70  
    22    <h1 class="mt-3 mb-3">Мои достави</h1>
    33    <form class="form-signin mt-xl-5" method="get" action="/myNextDeliveries">
    4     <button id="submit" class="btn btn-lg btn-primary btn-block w-50" type="submit">Мои следни нарачки</button>
     4    <button id="submit" class="btn btn-lg btn-primary btn-block w-50" type="submit">Мои следни достави</button>
    55    </form>
    66    <table class="table table-bordered mt-3">
  • src/main/resources/templates/myNextDeliveries.html

    r89865ae r4d67d70  
    11<div>
    2   <h1 class="mb-3 mt-3">Мои следни нарачки</h1>
     2  <h1 class="mb-3 mt-3">Мои следни достави</h1>
    33  <h1 th:if="${hasError}" th:text="${error}"></h1>
    44  <div th:if="${!hasError}">
Note: See TracChangeset for help on using the changeset viewer.