1 | package tech.techharbor.Web;
|
---|
2 |
|
---|
3 | import jakarta.servlet.http.HttpSession;
|
---|
4 | import org.springframework.stereotype.Controller;
|
---|
5 | import org.springframework.ui.Model;
|
---|
6 | import org.springframework.web.bind.annotation.GetMapping;
|
---|
7 | import org.springframework.web.bind.annotation.PathVariable;
|
---|
8 | import org.springframework.web.bind.annotation.PostMapping;
|
---|
9 | import org.springframework.web.bind.annotation.RequestParam;
|
---|
10 | import tech.techharbor.Model.UserTableModel;
|
---|
11 | import tech.techharbor.Service.DeliveryService;
|
---|
12 | import tech.techharbor.Service.OrderTableService;
|
---|
13 |
|
---|
14 |
|
---|
15 | @Controller
|
---|
16 | public 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 | }
|
---|