- Timestamp:
- 01/06/23 19:17:05 (23 months ago)
- Branches:
- main
- Children:
- cab5859
- Parents:
- d4b888e
- File:
-
- 1 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 }
Note:
See TracChangeset
for help on using the changeset viewer.