From 75071fdc1d93651225eff6ac35de5d82d8db3fba Mon Sep 17 00:00:00 2001 From: Katerina881 Date: Mon, 24 Apr 2023 16:02:44 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9F=D1=80=D0=B8=D0=BD=D1=8F=D1=82=D0=B0?= =?UTF-8?q?=D1=8F=20=D0=BB=D0=B0=D0=B1=D0=BE=D1=80=D0=B0=D1=82=D0=BE=D1=80?= =?UTF-8?q?=D0=BD=D0=B0=D1=8F=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../shop/controller/OrderMvcController.java | 55 ++++++-------- src/main/resources/templates/default.html | 1 + src/main/resources/templates/order-view.html | 71 +++++++++++++++++++ src/main/resources/templates/orders.html | 43 +++++++++++ 4 files changed, 135 insertions(+), 35 deletions(-) create mode 100644 src/main/resources/templates/order-view.html create mode 100644 src/main/resources/templates/orders.html 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 @@ + + + + +
+
+ + + + + + + + + + + + + + + +
#Дата оформленияОбщая стоимостьСтатус
+ + + + + +
+
+
+ +