source: src/main/java/com/example/salonbella/controller/order/OrderController.java@ 4d7e387

Last change on this file since 4d7e387 was 4d7e387, checked in by makyjovanovsky <mjovanovski04@…>, 18 months ago

commit 1

  • Property mode set to 100644
File size: 2.6 KB
Line 
1package com.example.salonbella.controller.order;
2
3import com.example.salonbella.service.ProductService;
4import com.example.salonbella.service.order.OrderService;
5import com.example.salonbella.service.ShoppingCartService;
6import org.springframework.beans.factory.annotation.Autowired;
7import org.springframework.stereotype.Controller;
8import org.springframework.ui.Model;
9import org.springframework.web.bind.annotation.GetMapping;
10import org.springframework.web.bind.annotation.PostMapping;
11import org.springframework.web.bind.annotation.RequestParam;
12
13import java.util.Map;
14
15@Controller
16public class OrderController {
17
18 private final OrderService orderService;
19 private final ShoppingCartService shoppingCartService;
20 private final ProductService productService;
21
22 @Autowired
23 public OrderController(OrderService orderService, ShoppingCartService shoppingCartService, ProductService productService) {
24 this.orderService = orderService;
25 this.shoppingCartService = shoppingCartService;
26 this.productService = productService;
27 }
28
29
30
31 @PostMapping("/order")
32 public String order(@RequestParam Map<String, String> allParams) {
33 orderService.changeQuantities(allParams, shoppingCartService.getShoppingCart());
34 orderService.saveOrder(shoppingCartService.getShoppingCart());
35 orderService.clearCart(shoppingCartService.getShoppingCart());
36 return "redirect:/userDashboard";
37 }
38
39 @GetMapping("/my-orders")
40 public String getMyOrders(Model model) {
41 model.addAttribute("orders", orderService.getUserOrders());
42 return "user-my-orders";
43 }
44
45 @PostMapping("/cancel-order")
46 public String cancelOrder(@RequestParam(name = "id") String id) {
47 orderService.cancelOrder(Long.parseLong(id));
48 return "redirect:/my-orders";
49 }
50
51 @GetMapping("/admin-get-orders")
52 public String getOrders(Model model) {
53 model.addAttribute("orders", orderService.getAllOrders());
54 return "admin-orders";
55 }
56
57 @PostMapping("/admin-change-status")
58 public String changeOrderStatus(@RequestParam(name = "id") String id) {
59 orderService.changeOrderStatus(Long.parseLong(id));
60 return "redirect:/admin-get-orders";
61 }
62
63 @PostMapping("/admin-cancel-order")
64 public String cancelOrderAdmin(@RequestParam(name = "id") String id) {
65 orderService.cancelOrderAdmin(Long.parseLong(id));
66 return "redirect:/admin-get-orders";
67 }
68
69 @GetMapping("/order")
70 public String getOrderPage(Model model) {
71 model.addAttribute("products", productService.getProducts());
72 return "user-order";
73 }
74}
Note: See TracBrowser for help on using the repository browser.