Принятая лабораторная работа
This commit is contained in:
parent
b741f13f4d
commit
75071fdc1d
@ -26,14 +26,17 @@ public class OrderMvcController {
|
|||||||
@GetMapping
|
@GetMapping
|
||||||
public String getOrders(HttpServletRequest request,
|
public String getOrders(HttpServletRequest request,
|
||||||
Model model) {
|
Model model) {
|
||||||
|
|
||||||
Cookie[] cookies = request.getCookies();
|
Cookie[] cookies = request.getCookies();
|
||||||
List<ProductDTO> productDTOS = new ArrayList<>();
|
List<ProductDTO> productDTOS = new ArrayList<>();
|
||||||
int totalPrice = 0;
|
int totalPrice = 0;
|
||||||
for(Cookie cookie : cookies){
|
if (cookies != null){
|
||||||
if (StringUtils.isNumeric(cookie.getName())){
|
for(Cookie cookie : cookies){
|
||||||
ProductDTO productDTO = new ProductDTO(productService.findProduct(Long.parseLong(cookie.getName())),Integer.parseInt(cookie.getValue()));
|
if (StringUtils.isNumeric(cookie.getName())){
|
||||||
productDTOS.add(productDTO);
|
ProductDTO productDTO = new ProductDTO(productService.findProduct(Long.parseLong(cookie.getName())),Integer.parseInt(cookie.getValue()));
|
||||||
totalPrice += productDTO.getPrice() * productDTO.getCount();
|
productDTOS.add(productDTO);
|
||||||
|
totalPrice += productDTO.getPrice() * productDTO.getCount();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
model.addAttribute("productDTOS", productDTOS);
|
model.addAttribute("productDTOS", productDTOS);
|
||||||
@ -61,34 +64,16 @@ public class OrderMvcController {
|
|||||||
response.addCookie(new Cookie("delete",""));
|
response.addCookie(new Cookie("delete",""));
|
||||||
return "redirect:/order";
|
return "redirect:/order";
|
||||||
}
|
}
|
||||||
// @PostMapping("/delete/{id}")
|
@GetMapping(value = {"/all"})
|
||||||
// public String deleteProduct(@PathVariable(required = false) Long id, HttpServletRequest request, Model model, HttpServletResponse response){
|
public String getOrders(Model model) {
|
||||||
// Cookie[] cookies = request.getCookies();
|
model.addAttribute("orders", orderService.findAllOrder());
|
||||||
// List<ProductDTO> productDTOS = new ArrayList<>();
|
return "orders";
|
||||||
// int totalPrice = 0;
|
}
|
||||||
// for(Cookie temp : cookies){
|
|
||||||
// if (StringUtils.isNumeric(temp.getName())){
|
@GetMapping(value = {"/view/{id}"})
|
||||||
// ProductDTO productDTO;
|
public String getOrder(@PathVariable(required = false) Long id,
|
||||||
// if(Long.parseLong(temp.getName()) == id){
|
Model model) {
|
||||||
// if (Objects.equals(temp.getValue(), "") || Integer.parseInt(temp.getValue()) == 1){
|
model.addAttribute("orderDto", new OrderDTO(orderService.findOrder(id)));
|
||||||
// Cookie userNameCookieRemove = new Cookie(temp.getName(), "");
|
return "order-view";
|
||||||
// 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";
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
@ -44,6 +44,7 @@
|
|||||||
>
|
>
|
||||||
<a class="nav-link fs-4 text-black" href="/product">Продукты</a>
|
<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">Заказы</a>
|
||||||
|
<a class="nav-link fs-4 text-black" href="/order/all">История заказов</a>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</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