- Timestamp:
- 01/06/23 19:17:05 (23 months ago)
- Branches:
- main
- Children:
- cab5859
- Parents:
- d4b888e
- Location:
- src/main
- Files:
-
- 5 added
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
src/main/java/com/example/autopartz/controller/HomeController.java
rd4b888e r9dcbf44 2 2 3 3 import com.example.autopartz.model.*; 4 import com.example.autopartz.model.DTO.OrderInfo; 5 import com.example.autopartz.model.manytomany.OrderContainsPart; 4 6 import com.example.autopartz.model.manytomany.PartIsInStockInWarehouse; 7 import com.example.autopartz.model.views.DeliveriesInProgress; 8 import com.example.autopartz.model.views.PartsForCarTypeAndCategory; 5 9 import com.example.autopartz.repository.*; 6 10 import com.example.autopartz.service.*; 7 11 import org.springframework.stereotype.Controller; 8 12 import 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; 13 import org.springframework.web.bind.annotation.*; 13 14 14 15 import javax.servlet.http.HttpServletRequest; … … 16 17 import javax.servlet.http.HttpSession; 17 18 import java.io.IOException; 19 import java.util.ArrayList; 18 20 import java.util.List; 19 21 import java.util.Objects; … … 32 34 private final OrderService orderService; 33 35 private final UserService userService; 36 private final DeliveriesInProgressRepository deliveriesInProgressRepository; 34 37 private final DeliveryService deliveryService; 35 38 private final PartIsInStockInWarehouseRepository partIsInStockInWarehouseRepository; 36 39 public HomeController(LoginService loginService, PartService partService, PartsForCarTypeAndCategoryRepository partsForCarTypeAndCategoryRepository, CarService carService, CategoryService categoryService, RepairShopReviewSummaryRepository repairShopReviewSummaryRepository, WarehouseRepository warehouseRepository, 37 OrderContainsPartRepository orderContainsPartRepository, OrderService orderService, UserService userService, Deliver yService deliveryService, PartIsInStockInWarehouseRepository partIsInStockInWarehouseRepository) {40 OrderContainsPartRepository orderContainsPartRepository, OrderService orderService, UserService userService, DeliveriesInProgressRepository deliveriesInProgressRepository, DeliveryService deliveryService, PartIsInStockInWarehouseRepository partIsInStockInWarehouseRepository) { 38 41 this.loginService = loginService; 39 42 this.partService = partService; … … 46 49 this.orderService = orderService; 47 50 this.userService = userService; 51 this.deliveriesInProgressRepository = deliveriesInProgressRepository; 48 52 this.deliveryService = deliveryService; 49 53 this.partIsInStockInWarehouseRepository = partIsInStockInWarehouseRepository; … … 87 91 @GetMapping("/filtered") 88 92 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 } 90 102 model.addAttribute("bodyContent","filteredParts"); 91 103 return "master-template"; … … 179 191 return "master-template"; 180 192 } 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 } 181 233 } -
src/main/java/com/example/autopartz/repository/DeliveryRepository.java
rd4b888e r9dcbf44 3 3 import com.example.autopartz.model.Delivery; 4 4 import com.example.autopartz.model.Deliveryman; 5 import com.example.autopartz.model.Order; 5 6 import org.springframework.data.jpa.repository.JpaRepository; 6 7 import org.springframework.stereotype.Repository; … … 11 12 public interface DeliveryRepository extends JpaRepository<Delivery,Integer> { 12 13 List<Delivery> findAllByDeliveryman(Deliveryman deliveryman); 14 List<Delivery> findAllByOrder(Order order); 13 15 } -
src/main/java/com/example/autopartz/service/DeliveryService.java
rd4b888e r9dcbf44 3 3 import com.example.autopartz.model.Delivery; 4 4 import com.example.autopartz.model.Deliveryman; 5 import com.example.autopartz.model.Order; 5 6 6 7 import java.util.List; … … 8 9 public interface DeliveryService { 9 10 List<Delivery> findAllByDeliverer(Deliveryman dm); 11 Delivery findById(Integer id); 12 void update(Delivery d); 13 Delivery findByOrder(Order o); 10 14 } -
src/main/java/com/example/autopartz/service/impl/DeliveryServiceImpl.java
rd4b888e r9dcbf44 3 3 import com.example.autopartz.model.Delivery; 4 4 import com.example.autopartz.model.Deliveryman; 5 import com.example.autopartz.model.Order; 5 6 import com.example.autopartz.repository.DeliveryRepository; 6 7 import com.example.autopartz.service.DeliveryService; … … 21 22 return deliveryRepository.findAllByDeliveryman(dm); 22 23 } 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 } 23 39 } -
src/main/resources/templates/filteredParts.html
rd4b888e r9dcbf44 1 1 <div> 2 <h1 >Резултат од филтерот</h1>2 <h1 class="mt-3 mb-3">Резултат од филтерот</h1> 3 3 <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"> 7 8 <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> 11 12 </tr> 12 13 </thead> … … 17 18 <td> 18 19 <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> 20 21 </form> 21 22 </td> … … 23 24 </tbody> 24 25 </table> 25 26 </div> 26 27 </div> -
src/main/resources/templates/myDeliveries.html
rd4b888e r9dcbf44 1 1 <div> 2 2 <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> 3 6 <table> 4 7 <thead> -
src/main/resources/templates/partinfo.html
rd4b888e r9dcbf44 1 1 <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 6 21 <form method="post" th:action="@{'/part/addToOrder/{id}' (id=${part.getId()}) }"> 7 22 <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="Количина"/> 9 24 </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> 11 26 </form> 12 27 </div> -
src/main/resources/templates/products.html
rd4b888e r9dcbf44 9 9 </header> 10 10 <main> 11 <h1 >Сите производи</h1>11 <h1 class="mt-3 mb-3">Сите производи</h1> 12 12 <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"> 14 14 <option th:each="car : ${cars}" 15 15 th:text="${car.getCartype()}" … … 17 17 </option> 18 18 </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"> 20 20 <option th:each="cat : ${categories}" 21 21 th:text="${cat.getCname()}" … … 23 23 </option> 24 24 </select> 25 <button type="submit">Филтрирај</button>25 <button class="btn btn-lg btn-block btn-primary w-25 d-inline" type="submit">Филтрирај</button> 26 26 </form> 27 <table >28 <thead >27 <table class="table table-bordered mt-4"> 28 <thead class="thead-dark"> 29 29 <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> 33 33 </tr> 34 34 </thead> … … 39 39 <td> 40 40 <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> 42 42 </form> 43 43 </td> -
src/main/resources/templates/services.html
rd4b888e r9dcbf44 1 1 <div> 2 2 <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"> 6 6 <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> 10 10 </tr> 11 11 </thead>
Note:
See TracChangeset
for help on using the changeset viewer.