source: src/main/java/tech/techharbor/Web/DeliveryController.java

main
Last change on this file was f4b4afa, checked in by Nikola Todoroski <nikola.todoroski@…>, 6 months ago

Pushed whole project, original project location on github:https://github.com/hehxd/Tech-Harbor

  • Property mode set to 100644
File size: 2.1 KB
RevLine 
[f4b4afa]1package tech.techharbor.Web;
2
3import jakarta.servlet.http.HttpSession;
4import org.springframework.stereotype.Controller;
5import org.springframework.ui.Model;
6import org.springframework.web.bind.annotation.GetMapping;
7import org.springframework.web.bind.annotation.PathVariable;
8import org.springframework.web.bind.annotation.PostMapping;
9import org.springframework.web.bind.annotation.RequestParam;
10import tech.techharbor.Model.UserTableModel;
11import tech.techharbor.Service.DeliveryService;
12import tech.techharbor.Service.OrderTableService;
13
14
15@Controller
16public class DeliveryController {
17
18 private final DeliveryService deliveryService;
19 private final OrderTableService orderTableService;
20
21 public DeliveryController(DeliveryService deliveryService, OrderTableService orderTableService) {
22 this.deliveryService = deliveryService;
23 this.orderTableService = orderTableService;
24 }
25
26 @GetMapping("/myDeliveries/{id}")
27 public String getDeliveryPage(@PathVariable Integer id, Model model, HttpSession session) {
28 Object deliveryManObject = session.getAttribute("deliveryMan");
29 model.addAttribute("deliveryMan", deliveryManObject);
30 UserTableModel deliveryMan = (UserTableModel) deliveryManObject;
31 model.addAttribute("deliveries", deliveryService.findByDeliveryManId(deliveryMan.getUserId()));
32
33 return "myDeliveries";
34 }
35
36 @PostMapping("/update-delivery-status")
37 public String updateDeliveryStatus(@RequestParam("deliveryId") Integer deliveryId,
38 @RequestParam("orderId") Integer orderId,
39 @RequestParam("newStatus") String newStatus,
40 HttpSession session) {
41
42 Object deliveryManObject = session.getAttribute("deliveryMan");
43 UserTableModel deliveryMan = (UserTableModel) deliveryManObject;
44 deliveryService.updateDeliveryStatus(deliveryId, newStatus);
45 orderTableService.updateOrderStatus(orderId, newStatus);
46 return "redirect:/myDeliveries/" + deliveryMan.getUserId();
47 }
48
49}
Note: See TracBrowser for help on using the repository browser.