LabWork05 #1
@ -26,14 +26,17 @@ public class OrderMvcController {
|
||||
@GetMapping
|
||||
public String getOrders(HttpServletRequest request,
|
||||
Model model) {
|
||||
|
||||
Cookie[] cookies = request.getCookies();
|
||||
List<ProductDTO> 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<ProductDTO> 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";
|
||||
}
|
||||
}
|
||||
|
@ -44,6 +44,7 @@
|
||||
>
|
||||
<a class="nav-link fs-4 text-black" href="/product">Продукты</a>
|
||||
<a class="nav-link fs-4 text-black" href="/order">Заказы</a>
|
||||
<a class="nav-link fs-4 text-black" href="/order/all">История заказов</a>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
71
src/main/resources/templates/order-view.html
Normal file
71
src/main/resources/templates/order-view.html
Normal file
@ -0,0 +1,71 @@
|
||||
<!DOCTYPE html>
|
||||
<html
|
||||
lang="en"
|
||||
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
|
||||
layout:decorate="~{default}"
|
||||
>
|
||||
<head>
|
||||
<script
|
||||
type="text/javascript"
|
||||
src="/webjars/jquery/3.6.0/jquery.min.js"
|
||||
></script>
|
||||
</head>
|
||||
<body>
|
||||
<main style="background-color: white" layout:fragment="content">
|
||||
<div th:text="${errors}" class="margin-bottom alert-danger"></div>
|
||||
<div class="mb-3">
|
||||
<label for="name" class="form-label">Дата</label>
|
||||
<input
|
||||
type="text"
|
||||
class="form-control"
|
||||
id="name"
|
||||
th:field="${orderDto.date}"
|
||||
disabled
|
||||
required="true"
|
||||
/>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="price" class="form-label">Общая стоимость</label>
|
||||
<input
|
||||
type="text"
|
||||
class="form-control"
|
||||
id="price"
|
||||
th:value="${orderDto.price}"
|
||||
disabled
|
||||
required="true"
|
||||
/>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="image" class="form-label">Статус</label>
|
||||
<input type="text" class="form-control" disabled id="image" th:value="${orderDto.status}" />
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<a class="btn btn-secondary button-fixed" th:href="@{/order/all}">
|
||||
Назад
|
||||
</a>
|
||||
</div>
|
||||
<div class="table-responsive" th:if="${id != null}">
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">Название</th>
|
||||
<th scope="col">Количество</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr
|
||||
th:each="product, iterator: ${orderDto.getProductDTOList()}"
|
||||
>
|
||||
<th
|
||||
scope="row"
|
||||
th:text="${product.getName()}"
|
||||
style="width: 60%"
|
||||
/>
|
||||
<td th:text="${product.getCount()}" />
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</main>
|
||||
</body>
|
||||
</html>
|
43
src/main/resources/templates/orders.html
Normal file
43
src/main/resources/templates/orders.html
Normal file
@ -0,0 +1,43 @@
|
||||
<!DOCTYPE html>
|
||||
<html
|
||||
lang="en"
|
||||
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
|
||||
layout:decorate="~{default}"
|
||||
>
|
||||
<head> </head>
|
||||
<body>
|
||||
<main style="background-color: white" layout:fragment="content">
|
||||
<div class="table-responsive">
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">#</th>
|
||||
<th scope="col">Дата оформления</th>
|
||||
<th scope="col">Общая стоимость</th>
|
||||
<th scope="col">Статус</th>
|
||||
<th scope="col"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr th:each="order, iterator: ${orders}">
|
||||
<th scope="row" th:text="${iterator.index} + 1" />
|
||||
<td th:text="${order.date}" style="width: 60%"/>
|
||||
<td th:text="${order.price}" />
|
||||
<td th:text="${order.status}" />
|
||||
<td style="width: 10%">
|
||||
<div class="btn-group" role="group" aria-label="Basic example">
|
||||
<a
|
||||
class="btn btn-warning button-fixed button-sm"
|
||||
th:href="@{/order/view/{id}(id=${order.id})}"
|
||||
>
|
||||
<i class="fa fa-pencil" aria-hidden="true"></i> Подробнее
|
||||
</a>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</main>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue
Block a user