diff --git a/src/main/java/ip/labwork/shop/controller/OrderMvcController.java b/src/main/java/ip/labwork/shop/controller/OrderMvcController.java index e25d933..c71601a 100644 --- a/src/main/java/ip/labwork/shop/controller/OrderMvcController.java +++ b/src/main/java/ip/labwork/shop/controller/OrderMvcController.java @@ -26,14 +26,17 @@ public class OrderMvcController { @GetMapping public String getOrders(HttpServletRequest request, Model model) { + Cookie[] cookies = request.getCookies(); List productDTOS = new ArrayList<>(); int totalPrice = 0; - for(Cookie cookie : cookies){ - if (StringUtils.isNumeric(cookie.getName())){ - ProductDTO productDTO = new ProductDTO(productService.findProduct(Long.parseLong(cookie.getName())),Integer.parseInt(cookie.getValue())); - productDTOS.add(productDTO); - totalPrice += productDTO.getPrice() * productDTO.getCount(); + if (cookies != null){ + for(Cookie cookie : cookies){ + if (StringUtils.isNumeric(cookie.getName())){ + ProductDTO productDTO = new ProductDTO(productService.findProduct(Long.parseLong(cookie.getName())),Integer.parseInt(cookie.getValue())); + productDTOS.add(productDTO); + totalPrice += productDTO.getPrice() * productDTO.getCount(); + } } } model.addAttribute("productDTOS", productDTOS); @@ -61,34 +64,16 @@ public class OrderMvcController { response.addCookie(new Cookie("delete","")); return "redirect:/order"; } -// @PostMapping("/delete/{id}") -// public String deleteProduct(@PathVariable(required = false) Long id, HttpServletRequest request, Model model, HttpServletResponse response){ -// Cookie[] cookies = request.getCookies(); -// List productDTOS = new ArrayList<>(); -// int totalPrice = 0; -// for(Cookie temp : cookies){ -// if (StringUtils.isNumeric(temp.getName())){ -// ProductDTO productDTO; -// if(Long.parseLong(temp.getName()) == id){ -// if (Objects.equals(temp.getValue(), "") || Integer.parseInt(temp.getValue()) == 1){ -// Cookie userNameCookieRemove = new Cookie(temp.getName(), ""); -// userNameCookieRemove.setMaxAge(-1); -// response.addCookie(userNameCookieRemove); -// continue; -// } -// productDTO = new ProductDTO(productService.findProduct(Long.parseLong(temp.getName())),Integer.parseInt(temp.getValue())-1); -// temp.setValue(productDTO.getCount()+""); -// temp.setMaxAge(-1); -// response.addCookie(temp); -// }else{ -// productDTO = new ProductDTO(productService.findProduct(Long.parseLong(temp.getName())),Integer.parseInt(temp.getValue())); -// } -// productDTOS.add(productDTO); -// totalPrice += productDTO.getPrice() * productDTO.getCount(); -// } -// } -// model.addAttribute("productDTOS", productDTOS); -// model.addAttribute("totalPrice", totalPrice); -// return "order"; -// } + @GetMapping(value = {"/all"}) + public String getOrders(Model model) { + model.addAttribute("orders", orderService.findAllOrder()); + return "orders"; + } + + @GetMapping(value = {"/view/{id}"}) + public String getOrder(@PathVariable(required = false) Long id, + Model model) { + model.addAttribute("orderDto", new OrderDTO(orderService.findOrder(id))); + return "order-view"; + } } diff --git a/src/main/resources/templates/default.html b/src/main/resources/templates/default.html index 70ca687..80229db 100644 --- a/src/main/resources/templates/default.html +++ b/src/main/resources/templates/default.html @@ -44,6 +44,7 @@ > Продукты Заказы + История заказов diff --git a/src/main/resources/templates/order-view.html b/src/main/resources/templates/order-view.html new file mode 100644 index 0000000..8250257 --- /dev/null +++ b/src/main/resources/templates/order-view.html @@ -0,0 +1,71 @@ + + + + + + +
+
+
+ + +
+
+ + +
+
+ + +
+ +
+ + + + + + + + + + + +
НазваниеКоличество
+ +
+
+
+ + diff --git a/src/main/resources/templates/orders.html b/src/main/resources/templates/orders.html new file mode 100644 index 0000000..a3366f9 --- /dev/null +++ b/src/main/resources/templates/orders.html @@ -0,0 +1,43 @@ + + + + +
+
+ + + + + + + + + + + + + + + +
#Дата оформленияОбщая стоимостьСтатус
+ + + + + +
+
+
+ +