[4d7e387] | 1 | package com.example.salonbella.controller.order;
|
---|
| 2 |
|
---|
| 3 | import com.example.salonbella.service.ProductService;
|
---|
| 4 | import com.example.salonbella.service.order.OrderService;
|
---|
| 5 | import com.example.salonbella.service.ShoppingCartService;
|
---|
| 6 | import org.springframework.beans.factory.annotation.Autowired;
|
---|
| 7 | import org.springframework.stereotype.Controller;
|
---|
| 8 | 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.RequestParam;
|
---|
| 12 |
|
---|
| 13 | import java.util.Map;
|
---|
| 14 |
|
---|
| 15 | @Controller
|
---|
| 16 | public 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 | }
|
---|