Changeset 9dcbf44


Ignore:
Timestamp:
01/06/23 19:17:05 (18 months ago)
Author:
andrejtodorovski <82031894+andrejtodorovski@…>
Branches:
main
Children:
cab5859
Parents:
d4b888e
Message:

Added full functionality for changing delivery status,
added bootstrap for some pages

Location:
src/main
Files:
5 added
9 edited

Legend:

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

    rd4b888e r9dcbf44  
    22
    33import com.example.autopartz.model.*;
     4import com.example.autopartz.model.DTO.OrderInfo;
     5import com.example.autopartz.model.manytomany.OrderContainsPart;
    46import com.example.autopartz.model.manytomany.PartIsInStockInWarehouse;
     7import com.example.autopartz.model.views.DeliveriesInProgress;
     8import com.example.autopartz.model.views.PartsForCarTypeAndCategory;
    59import com.example.autopartz.repository.*;
    610import com.example.autopartz.service.*;
    711import org.springframework.stereotype.Controller;
    812import org.springframework.ui.Model;
    9 import org.springframework.web.bind.annotation.GetMapping;
    10 import org.springframework.web.bind.annotation.PostMapping;
    11 import org.springframework.web.bind.annotation.RequestMapping;
    12 import org.springframework.web.bind.annotation.RequestParam;
     13import org.springframework.web.bind.annotation.*;
    1314
    1415import javax.servlet.http.HttpServletRequest;
     
    1617import javax.servlet.http.HttpSession;
    1718import java.io.IOException;
     19import java.util.ArrayList;
    1820import java.util.List;
    1921import java.util.Objects;
     
    3234    private final OrderService orderService;
    3335    private final UserService userService;
     36    private final DeliveriesInProgressRepository deliveriesInProgressRepository;
    3437    private final DeliveryService deliveryService;
    3538    private final PartIsInStockInWarehouseRepository partIsInStockInWarehouseRepository;
    3639    public HomeController(LoginService loginService, PartService partService, PartsForCarTypeAndCategoryRepository partsForCarTypeAndCategoryRepository, CarService carService, CategoryService categoryService, RepairShopReviewSummaryRepository repairShopReviewSummaryRepository, WarehouseRepository warehouseRepository,
    37                           OrderContainsPartRepository orderContainsPartRepository, OrderService orderService, UserService userService, DeliveryService deliveryService, PartIsInStockInWarehouseRepository partIsInStockInWarehouseRepository) {
     40                          OrderContainsPartRepository orderContainsPartRepository, OrderService orderService, UserService userService, DeliveriesInProgressRepository deliveriesInProgressRepository, DeliveryService deliveryService, PartIsInStockInWarehouseRepository partIsInStockInWarehouseRepository) {
    3841        this.loginService = loginService;
    3942        this.partService = partService;
     
    4649        this.orderService = orderService;
    4750        this.userService = userService;
     51        this.deliveriesInProgressRepository = deliveriesInProgressRepository;
    4852        this.deliveryService = deliveryService;
    4953        this.partIsInStockInWarehouseRepository = partIsInStockInWarehouseRepository;
     
    8791    @GetMapping("/filtered")
    8892    public String getPartsForCarTypeAndCategory(@RequestParam String cartype, @RequestParam String category, Model model){
    89         model.addAttribute("filtered", partsForCarTypeAndCategoryRepository.findAllByCartypeAndCategory(cartype,category));
     93        List<PartsForCarTypeAndCategory> tmp = partsForCarTypeAndCategoryRepository.findAllByCartypeAndCategory(cartype,category);
     94        if(tmp.size()==0){
     95            model.addAttribute("hasError",true);
     96            model.addAttribute("error","Не постојат такви производи, обидете се повторно");
     97        }
     98        else {
     99            model.addAttribute("hasError",false);
     100            model.addAttribute("filtered", tmp);
     101        }
    90102        model.addAttribute("bodyContent","filteredParts");
    91103        return "master-template";
     
    179191        return "master-template";
    180192    }
     193    @GetMapping("myNextDeliveries")
     194    public String myNextDeliveries(Model model, HttpServletRequest request){
     195        Deliveryman dm = (Deliveryman) userService.findByUsername(request.getRemoteUser());
     196        List<DeliveriesInProgress> ldip = deliveriesInProgressRepository.findAllByUserid(dm.getId());
     197        if(ldip.size()==0){
     198            model.addAttribute("hasError",true);
     199            model.addAttribute("error","Сите достави се завршени");
     200        }
     201        else {
     202            model.addAttribute("hasError",false);
     203            model.addAttribute("deliveries", deliveriesInProgressRepository.findAllByUserid(dm.getId()));
     204        }
     205        model.addAttribute("bodyContent","myNextDeliveries");
     206        return "master-template";
     207    }
     208    @PostMapping("/finishDelivery/{id}")
     209    public void finishDelivery(@PathVariable Integer id, Model model, HttpServletResponse response){
     210        Delivery d = deliveryService.findByOrder(orderService.findById(id));
     211        d.setStatus("finished");
     212        deliveryService.update(d);
     213        try {
     214            response.sendRedirect("/myDeliveries");
     215        } catch (IOException e) {
     216            throw new RuntimeException(e);
     217        }
     218    }
     219    @GetMapping("/order/{id}")
     220    public String getOrderInfo(@PathVariable Integer id, Model model){
     221        List<OrderContainsPart> list = orderContainsPartRepository.findAllByOrderid(id);
     222        List<OrderInfo> partList = new ArrayList<>();
     223        for (int i = 0; i < list.size(); i++) {
     224            OrderInfo oi = new OrderInfo(partService.findById(list.get(i).getPartid()).getName(),
     225                    list.get(i).getQuantity_order(),partService.findById(list.get(i).getPartid()).getManufacturer().getName());
     226            partList.add(oi);
     227        }
     228        model.addAttribute("parts",partList);
     229        model.addAttribute("o",orderService.findById(id));
     230        model.addAttribute("bodyContent","orderInfo");
     231        return "master-template";
     232    }
    181233}
  • src/main/java/com/example/autopartz/repository/DeliveryRepository.java

    rd4b888e r9dcbf44  
    33import com.example.autopartz.model.Delivery;
    44import com.example.autopartz.model.Deliveryman;
     5import com.example.autopartz.model.Order;
    56import org.springframework.data.jpa.repository.JpaRepository;
    67import org.springframework.stereotype.Repository;
     
    1112public interface DeliveryRepository extends JpaRepository<Delivery,Integer> {
    1213    List<Delivery> findAllByDeliveryman(Deliveryman deliveryman);
     14    List<Delivery> findAllByOrder(Order order);
    1315}
  • src/main/java/com/example/autopartz/service/DeliveryService.java

    rd4b888e r9dcbf44  
    33import com.example.autopartz.model.Delivery;
    44import com.example.autopartz.model.Deliveryman;
     5import com.example.autopartz.model.Order;
    56
    67import java.util.List;
     
    89public interface DeliveryService {
    910    List<Delivery> findAllByDeliverer(Deliveryman dm);
     11    Delivery findById(Integer id);
     12    void update(Delivery d);
     13    Delivery findByOrder(Order o);
    1014}
  • src/main/java/com/example/autopartz/service/impl/DeliveryServiceImpl.java

    rd4b888e r9dcbf44  
    33import com.example.autopartz.model.Delivery;
    44import com.example.autopartz.model.Deliveryman;
     5import com.example.autopartz.model.Order;
    56import com.example.autopartz.repository.DeliveryRepository;
    67import com.example.autopartz.service.DeliveryService;
     
    2122        return deliveryRepository.findAllByDeliveryman(dm);
    2223    }
     24
     25    @Override
     26    public Delivery findById(Integer id) {
     27        return deliveryRepository.findById(id).get();
     28    }
     29
     30    @Override
     31    public void update(Delivery d) {
     32        deliveryRepository.save(d);
     33    }
     34
     35    @Override
     36    public Delivery findByOrder(Order o) {
     37        return deliveryRepository.findAllByOrder(o).stream().findFirst().orElseThrow(RuntimeException::new);
     38    }
    2339}
  • src/main/resources/templates/filteredParts.html

    rd4b888e r9dcbf44  
    11<div>
    2 <h1>Резултат од филтерот</h1>
     2<h1 class="mt-3 mb-3">Резултат од филтерот</h1>
    33<a th:href="${'/products'}">Врати се на сите производи</a>
    4 
    5 <table>
    6     <thead>
     4    <h3 th:if="${hasError}" th:text="${error}"></h3>
     5    <div th:if="${!hasError}">
     6<table class="table table-bordered mt-3">
     7    <thead class="thead-dark">
    78    <tr>
    8         <th>Name</th>
    9         <th>Manufacturer</th>
    10         <th>Details</th>
     9        <th scope="col">Име</th>
     10        <th scope="col">Производител</th>
     11        <th scope="col">Детали</th>
    1112    </tr>
    1213    </thead>
     
    1718        <td>
    1819            <form th:action="@{'/part/{id}' (id=${f.getPartid()}) }">
    19                 <button type="submit">Детали</button>
     20                <button class="btn btn-primary btn-block btn-lg w-50" type="submit">Детали</button>
    2021            </form>
    2122        </td>
     
    2324    </tbody>
    2425</table>
    25 
     26    </div>
    2627</div>
  • src/main/resources/templates/myDeliveries.html

    rd4b888e r9dcbf44  
    11<div>
    22    <h1>Мои достави</h1>
     3    <form class="form-signin mt-xl-5" method="get" action="/myNextDeliveries">
     4    <button id="submit" class="btn btn-lg btn-primary btn-block" type="submit">Мои следни нарачки</button>
     5    </form>
    36    <table>
    47        <thead>
  • src/main/resources/templates/partinfo.html

    rd4b888e r9dcbf44  
    11<div>
    2 <p th:text="${part.getName()}"></p>
    3 <p th:text="${part.getDescription()}"></p>
    4 <p th:text="${part.getManufacturer().getName()}"></p>
    5 <p><span th:text="${amount}"></span><span> денари</span></p>
     2    <table class="table table-bordered mt-4">
     3        <thead class="thead-dark">
     4        <tr>
     5            <th scope="col">Име</th>
     6            <th scope="col">Опис</th>
     7            <th scope="col">Производител</th>
     8            <th scope="col">Цена</th>
     9        </tr>
     10        </thead>
     11        <tbody>
     12        <tr>
     13            <td th:text="${part.getName()}"></td>
     14            <td th:text="${part.getDescription()}"></td>
     15            <td th:text="${part.getManufacturer().getName()}"></td>
     16            <td><span th:text="${amount}"></span><span> денари</span></td>
     17        </tr>
     18        </tbody>
     19    </table>
     20
    621<form method="post" th:action="@{'/part/addToOrder/{id}' (id=${part.getId()}) }">
    722    <label>
    8         <input type="number" name="quantity" required min="1" placeholder="Количина"/>
     23        <input class="form-control d-inline" type="number" name="quantity" required min="1" placeholder="Количина"/>
    924    </label>
    10     <button class="btn btn-primary btn-block btn-lg" type="submit">Додај во нарачка</button>
     25    <button class="btn btn-primary btn-block btn-lg w-25 d-inline" type="submit">Додај во нарачка</button>
    1126</form>
    1227</div>
  • src/main/resources/templates/products.html

    rd4b888e r9dcbf44  
    99</header>
    1010<main>
    11     <h1>Сите производи</h1>
     11    <h1 class="mt-3 mb-3">Сите производи</h1>
    1212    <form th:action="@{/filtered}">
    13         <label for="cartype"></label><select id="cartype" required name="cartype">
     13        <label for="cartype"></label><select id="cartype" class="form-control w-25 d-inline mr-3" required name="cartype">
    1414            <option  th:each="car : ${cars}"
    1515                     th:text="${car.getCartype()}"
     
    1717            </option>
    1818        </select>
    19         <label for="category"></label><select id="category" required name="category">
     19        <label for="category"></label><select id="category" class="form-control w-25 d-inline mr-3" required name="category">
    2020            <option  th:each="cat : ${categories}"
    2121                     th:text="${cat.getCname()}"
     
    2323            </option>
    2424        </select>
    25         <button type="submit">Филтрирај</button>
     25        <button class="btn btn-lg btn-block btn-primary w-25 d-inline" type="submit">Филтрирај</button>
    2626    </form>
    27     <table>
    28         <thead>
     27    <table class="table table-bordered mt-4">
     28        <thead class="thead-dark">
    2929        <tr>
    30             <th>Name</th>
    31             <th>Manufacturer</th>
    32             <th>Details</th>
     30            <th scope="col">Име</th>
     31            <th scope="col">Производител</th>
     32            <th scope="col">Детали</th>
    3333        </tr>
    3434        </thead>
     
    3939            <td>
    4040                <form th:action="@{'/part/{id}' (id=${part.getId()}) }">
    41                     <button type="submit">Детали</button>
     41                    <button class="btn btn-primary btn-block btn-lg w-50" type="submit">Детали</button>
    4242                </form>
    4343            </td>
  • src/main/resources/templates/services.html

    rd4b888e r9dcbf44  
    11<div>
    22  <main>
    3     <h1>Информации за сервиси</h1>
    4     <table>
    5       <thead>
     3    <h1 class="mt-3 mb-3">Информации за сервиси</h1>
     4    <table class="table table-bordered">
     5      <thead class="thead-dark">
    66      <tr>
    7         <th>Name</th>
    8         <th>Number of reviews</th>
    9         <th>Average rating</th>
     7        <th scope="col">Име на сервис</th>
     8        <th scope="col">Број на критики</th>
     9        <th scope="col">Просечна оценка</th>
    1010      </tr>
    1111      </thead>
Note: See TracChangeset for help on using the changeset viewer.