mirror of
https://github.com/st-tu-dresden-praktikum/swt23w23
synced 2024-07-19 21:04:36 +02:00
Update /allOrders/{day} to work with status-filter
This works on #115 Co-authored-by: Theo Reichert <theo.reichert@mailbox.tu-dresden.de>
This commit is contained in:
parent
da24ca79a1
commit
2ccc9fcdfb
|
@ -83,17 +83,20 @@ public class OrderController {
|
|||
|
||||
@GetMapping("/allOrders/{day}")
|
||||
@PreAuthorize("hasRole('ADMIN')")
|
||||
public String ordersForAdmin(@PathVariable String day, Model model) {
|
||||
public String ordersForAdmin(@PathVariable String day, Model model, @Valid @ModelAttribute("form") OrderQueryForm form) {
|
||||
// Obtains an instance of LocalDate from a text string such as 2007-12-03.
|
||||
LocalDate date = LocalDate.parse(day);
|
||||
|
||||
List<CustomOrder> myOrders = customOrderRepository.findOrdersByInterval(date.atStartOfDay(),
|
||||
date.atStartOfDay().plusHours(23).withMinute(59).withSecond(59))
|
||||
.stream().toList();
|
||||
.stream().filter(order -> order.getOrderStatus().equals(form.getOrderStatus().orElse(order.getOrderStatus()))).toList();
|
||||
|
||||
model.addAttribute("orders", myOrders);
|
||||
model.addAttribute("total", myOrders.size());
|
||||
model.addAttribute("form", new OrderQueryForm());
|
||||
model.addAttribute("cancelled", OrderStatus.CANCELED);
|
||||
model.addAttribute("completed", OrderStatus.COMPLETED);
|
||||
model.addAttribute("form", form);
|
||||
model.addAttribute("day", day);
|
||||
return "orders";
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<!--/*-->
|
||||
SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
SPDX-FileCopyrightText: 2023 swt23w23
|
||||
SPDX-FileCopyrightText: 2023-2024 swt23w23
|
||||
<!--*/-->
|
||||
<!DOCTYPE html>
|
||||
<html xmlns:th="http://www.thymeleaf.org"
|
||||
|
@ -9,8 +9,8 @@ SPDX-FileCopyrightText: 2023 swt23w23
|
|||
layout:decorate="~{layout.html(title='Bestellungen')}">
|
||||
<body>
|
||||
<div layout:fragment="content">
|
||||
<div> <!--th:unless"${cart.empty}"-->
|
||||
<form sec:authorize="hasRole('ADMIN')" method="get" th:action="@{/allOrders}" th:object="${form}" class="mb-3">
|
||||
<div>
|
||||
<form sec:authorize="hasRole('ADMIN')" method="get" th:action="@{'/allOrders' + ${day != null ? '/' + day : '' }}" th:object="${form}" class="mb-3">
|
||||
<label class="form-label">Bestellungsstatus</label>
|
||||
<select class="form-select mb-2" for="orderStatus" th:field="*{orderStatus}" th:errorclass="is-invalid">
|
||||
<option selected name="orderStatus" th:value="${null}" th:text="any"></option>
|
||||
|
@ -23,7 +23,7 @@ SPDX-FileCopyrightText: 2023 swt23w23
|
|||
/>
|
||||
</select>
|
||||
<div th:if="${#fields.hasErrors('orderStatus')}" class="invalid-feedback">Ungültiger Buchungsstatus.</div>
|
||||
<button class="btn btn-primary" type="submit" th:text="${'suchen'}"></button>
|
||||
<button class="btn btn-primary" type="submit">suchen</button>
|
||||
</form>
|
||||
<table class="table">
|
||||
<tr>
|
||||
|
|
Loading…
Reference in a new issue