mirror of
https://github.com/st-tu-dresden-praktikum/swt23w23
synced 2024-07-19 21:04:36 +02:00
Introduce new lines to reduce code smells
This commit is contained in:
parent
a78b225de9
commit
d27c1958d7
|
@ -41,10 +41,14 @@ public class OrderController {
|
|||
private final OrderManagement<CustomOrder> orderManagement;
|
||||
private final CustomOrderRepository customOrderRepository;
|
||||
private final UniqueInventory<UniqueInventoryItem> inventory;
|
||||
private final CateringCatalog catalog;
|
||||
private final CateringCatalog catalog;
|
||||
private final StaffManagement staffManagement;
|
||||
|
||||
public OrderController(OrderManagement<CustomOrder> orderManagement, CustomOrderRepository customOrderRepository, UniqueInventory<UniqueInventoryItem> inventory, CateringCatalog catalog, StaffManagement staffManagement) {
|
||||
public OrderController(OrderManagement<CustomOrder> orderManagement,
|
||||
CustomOrderRepository customOrderRepository,
|
||||
UniqueInventory<UniqueInventoryItem> inventory,
|
||||
CateringCatalog catalog,
|
||||
StaffManagement staffManagement) {
|
||||
this.orderManagement = orderManagement;
|
||||
this.customOrderRepository = customOrderRepository;
|
||||
this.catalog = catalog;
|
||||
|
@ -83,13 +87,16 @@ public class OrderController {
|
|||
|
||||
@GetMapping("/allOrders/{day}")
|
||||
@PreAuthorize("hasRole('ADMIN')")
|
||||
public String ordersForAdmin(@PathVariable String day, Model model, @Valid @ModelAttribute("form") OrderQueryForm form) {
|
||||
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().filter(order -> order.getOrderStatus().equals(form.getOrderStatus().orElse(order.getOrderStatus()))).toList();
|
||||
.stream().filter(order -> order.getOrderStatus()
|
||||
.equals(form.getOrderStatus().orElse(order.getOrderStatus()))).toList();
|
||||
|
||||
model.addAttribute("orders", myOrders);
|
||||
model.addAttribute("total", myOrders.size());
|
||||
|
@ -185,7 +192,9 @@ public class OrderController {
|
|||
|
||||
@PostMapping("/event/addProduct")
|
||||
@PreAuthorize("hasRole('CUSTOMER')")
|
||||
public String addProduct(@RequestParam("pid") Product product, @RequestParam("number") int number, @ModelAttribute("event") CustomCart cart) {
|
||||
public String addProduct(@RequestParam("pid") Product product,
|
||||
@RequestParam("number") int number,
|
||||
@ModelAttribute("event") CustomCart cart) {
|
||||
// check if product is suitable
|
||||
if (product.getCategories().stream().noneMatch(c -> c.equals(cart.getOrderType().toString()))) {
|
||||
return "redirect:/event";
|
||||
|
@ -226,7 +235,11 @@ public class OrderController {
|
|||
|
||||
@PostMapping("/event/changeDate")
|
||||
@PreAuthorize("hasRole('CUSTOMER')")
|
||||
public String changeDate(@RequestParam("startDate") LocalDate start, @RequestParam("startHour") Optional<Integer> startHour, @RequestParam("finishDate") LocalDate finish, @RequestParam("finishHour") Optional<Integer> finishHour, @ModelAttribute("event") CustomCart cart) {
|
||||
public String changeDate(@RequestParam("startDate") LocalDate start,
|
||||
@RequestParam("startHour") Optional<Integer> startHour,
|
||||
@RequestParam("finishDate") LocalDate finish,
|
||||
@RequestParam("finishHour") Optional<Integer> finishHour,
|
||||
@ModelAttribute("event") CustomCart cart) {
|
||||
|
||||
int unwrappedStartHour = startHour.orElse(cart.getStart().getHour());
|
||||
int unwrappedFinishHour = finishHour.orElse(cart.getFinish().getHour());
|
||||
|
@ -265,7 +278,8 @@ public class OrderController {
|
|||
|
||||
@PostMapping("/event/changeOrderType")
|
||||
@PreAuthorize("hasRole('CUSTOMER')")
|
||||
public String changeOrderType(@RequestParam(name = "type") String orderType, @ModelAttribute("event") CustomCart cart) {
|
||||
public String changeOrderType(@RequestParam(name = "type") String orderType,
|
||||
@ModelAttribute("event") CustomCart cart) {
|
||||
try {
|
||||
cart.setOrderType(OrderType.valueOf(orderType));
|
||||
} catch (IllegalArgumentException e) {
|
||||
|
@ -274,7 +288,11 @@ public class OrderController {
|
|||
return "redirect:/event";
|
||||
}
|
||||
|
||||
public static Quantity findFreeAmountInInterval(Rentable product, LocalDateTime start, LocalDateTime finish, UniqueInventory<UniqueInventoryItem> inventory, CustomOrderRepository customOrderRepository) {
|
||||
public static Quantity findFreeAmountInInterval(Rentable product,
|
||||
LocalDateTime start,
|
||||
LocalDateTime finish,
|
||||
UniqueInventory<UniqueInventoryItem> inventory,
|
||||
CustomOrderRepository customOrderRepository) {
|
||||
|
||||
return inventory.findByProduct(product)
|
||||
.map(item -> item.getQuantity().subtract(
|
||||
|
@ -304,7 +322,8 @@ public class OrderController {
|
|||
// add each order overlapping with the calendar to the days it overlaps with
|
||||
for (CustomOrder order : customOrderRepository.findOrdersByInterval(startDateTime, endDateTime)) {
|
||||
int start_index_inclusive = Math.max((int) startDate.until(order.getStart().toLocalDate(), ChronoUnit.DAYS),0);
|
||||
int end_index_exclusive = Math.min((int) startDate.until(order.getFinish().toLocalDate(), ChronoUnit.DAYS), 27) + 1;
|
||||
int end_index_exclusive = Math.min((int) startDate.until(
|
||||
order.getFinish().toLocalDate(), ChronoUnit.DAYS), 27) + 1;
|
||||
String order_id = Objects.requireNonNull(order.getId()).toString();
|
||||
for (int i = start_index_inclusive; i < end_index_exclusive; i++) {
|
||||
// FIXME: exchange order ids for a short name or a color
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
// SPDX-FileCopyrightText: 2023 swt23w23
|
||||
// SPDX-FileCopyrightText: 2023-2024 swt23w23
|
||||
package catering.orderCatalog;
|
||||
|
||||
import catering.order.OrderType;
|
||||
|
@ -23,7 +23,8 @@ public class CatalogController {
|
|||
private CustomCatalogEntry formCatalogEntry;
|
||||
private final UniqueInventory<UniqueInventoryItem> inventory;
|
||||
|
||||
public CatalogController(CustomCatalogEntryRepository catalogEntryRepository, UniqueInventory<UniqueInventoryItem> inventory) {
|
||||
public CatalogController(CustomCatalogEntryRepository catalogEntryRepository,
|
||||
UniqueInventory<UniqueInventoryItem> inventory) {
|
||||
productMap = new HashMap<>();
|
||||
formCatalogEntry = new CustomCatalogEntry(
|
||||
OrderType.EVENT_CATERING,
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
// SPDX-FileCopyrightText: 2023 swt23w23
|
||||
// SPDX-FileCopyrightText: 2023-2024 swt23w23
|
||||
package catering.users;
|
||||
|
||||
import static catering.users.UserForm.UserFormWithPassword.RegistrationForm;
|
||||
|
@ -129,7 +129,8 @@ public class UserController {
|
|||
@PreAuthorize("hasRole('ADMIN')")
|
||||
public String getCustomer(Model model) {
|
||||
model.addAttribute("title", "Kundenverwaltung");
|
||||
model.addAttribute("customers", userManagement.getUsers().findAll().stream().filter(customer -> customer.getUserAccount().hasRole(Role.of("CUSTOMER"))).toList());
|
||||
model.addAttribute("customers", userManagement.getUsers().findAll().stream()
|
||||
.filter(customer -> customer.getUserAccount().hasRole(Role.of("CUSTOMER"))).toList());
|
||||
return "customers";
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
// SPDX-FileCopyrightText: 2023 swt23w23
|
||||
// SPDX-FileCopyrightText: 2023-2024 swt23w23
|
||||
package catering.users;
|
||||
|
||||
import java.util.Optional;
|
||||
|
@ -31,11 +31,13 @@ public class UserManagement {
|
|||
String password,
|
||||
String fullName
|
||||
) {
|
||||
return users.save(new User(userAccounts.create(username,UnencryptedPassword.of(password),Role.of("CUSTOMER")),address,fullName));
|
||||
return users.save(new User(userAccounts.create(
|
||||
username,UnencryptedPassword.of(password),Role.of("CUSTOMER")),address,fullName));
|
||||
}
|
||||
|
||||
public User createAdmin(String name, String address, String password) {
|
||||
return users.save(new User(userAccounts.create(name,UnencryptedPassword.of(password),Role.of("ADMIN")), address, name));
|
||||
return users.save(new User(userAccounts.create(
|
||||
name,UnencryptedPassword.of(password),Role.of("ADMIN")), address, name));
|
||||
}
|
||||
|
||||
public User save(User user) {
|
||||
|
|
Loading…
Reference in a new issue