mirror of
https://github.com/st-tu-dresden-praktikum/swt23w23
synced 2024-07-19 21:04:36 +02:00
Add filteredByDay to OrderController
This commit is contained in:
parent
ac253f3df7
commit
0a24be51be
|
@ -2,10 +2,12 @@ package catering.order;
|
||||||
|
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.time.LocalDate;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class is only used for the prototype to avoid using the bloated Salespoint API
|
* This class is only used for the prototype to avoid using the bloated Salespoint API
|
||||||
|
@ -34,4 +36,12 @@ public class CustomOrderRepository {
|
||||||
public Collection<CustomOrder> getOrders() {
|
public Collection<CustomOrder> getOrders() {
|
||||||
return new ArrayList<>(this.orders);
|
return new ArrayList<>(this.orders);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// For Theo: returns all orders that happen on this day
|
||||||
|
public Collection<CustomOrder> getOrdersByDate(LocalDate date) {
|
||||||
|
return this.orders.stream().filter(order ->
|
||||||
|
(order.getStart().toLocalDate().isBefore(date) || order.getStart().toLocalDate().isEqual(date))
|
||||||
|
&& (order.getFinish().toLocalDate().isAfter(date) || order.getFinish().toLocalDate().isEqual(date))
|
||||||
|
).collect(Collectors.toList());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@ import org.springframework.web.bind.annotation.*;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
|
@ -30,6 +31,18 @@ public class OrderController {
|
||||||
return "orders";
|
return "orders";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// For Theo: filters orders by day
|
||||||
|
@GetMapping("/orders/{day}")
|
||||||
|
public String orders(@PathVariable String day, Model model) {
|
||||||
|
// Obtains an instance of LocalDate from a text string such as 2007-12-03. (https://docs.oracle.com/javase/8/docs/api/java/time/LocalDate.html)
|
||||||
|
LocalDate date = LocalDate.parse(day);
|
||||||
|
|
||||||
|
Collection<CustomOrder> myOrders = orderRepository.getOrdersByDate(date);
|
||||||
|
model.addAttribute("orders", myOrders);
|
||||||
|
model.addAttribute("total", myOrders.size());
|
||||||
|
return "orders";
|
||||||
|
}
|
||||||
|
|
||||||
@GetMapping("/event")
|
@GetMapping("/event")
|
||||||
public String event(Model model) {
|
public String event(Model model) {
|
||||||
model.addAttribute("orderType", cart.getOrderType());
|
model.addAttribute("orderType", cart.getOrderType());
|
||||||
|
|
Loading…
Reference in a new issue