From 5a59ac11b0cbb61ca292f4ba54e864e84ae3404f Mon Sep 17 00:00:00 2001 From: Hannes Date: Wed, 10 Jun 2020 18:45:52 +0200 Subject: [PATCH] code cleanup --- .../customers/CustomersIndexController.java | 32 +++++++++++-------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/prototype/src/main/java/org/hso/ecommerce/controller/intern/customers/CustomersIndexController.java b/prototype/src/main/java/org/hso/ecommerce/controller/intern/customers/CustomersIndexController.java index 72d2893..e0a49f4 100644 --- a/prototype/src/main/java/org/hso/ecommerce/controller/intern/customers/CustomersIndexController.java +++ b/prototype/src/main/java/org/hso/ecommerce/controller/intern/customers/CustomersIndexController.java @@ -7,21 +7,24 @@ import javax.servlet.http.HttpServletRequest; import org.hso.ecommerce.controller.intern.accounting.AccountingController; import org.hso.ecommerce.controller.intern.accounting.AccountingController.ShortTemplateBookingResult; import org.hso.ecommerce.entities.booking.Booking; -import org.hso.ecommerce.entities.booking.BookingAccountEntry; import org.hso.ecommerce.entities.shop.CustomerOrder; import org.hso.ecommerce.entities.user.User; -import org.hso.ecommerce.repos.booking.BookingAccountEntryRepository; import org.hso.ecommerce.repos.booking.BookingRepository; import org.hso.ecommerce.repos.shop.CustomerOrderRepository; import org.hso.ecommerce.repos.user.UserRepository; import org.springframework.beans.factory.annotation.Autowired; + +import java.util.List; + +import javax.servlet.http.HttpServletRequest; + +import org.hso.ecommerce.controller.intern.accounting.AccountingController; +import org.hso.ecommerce.controller.intern.accounting.AccountingController.ShortTemplateBookingResult; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.*; -import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import java.util.List; import java.util.Optional; @Controller @@ -42,9 +45,10 @@ public class CustomersIndexController { @GetMapping("") public String internCustomers(Model model) { + List users = userRepository.findAll(); + + model.addAttribute("users", users); - @GetMapping("/") - public String internCustomers() { return "intern/customers/index"; } @@ -55,7 +59,7 @@ public class CustomersIndexController { HttpServletRequest request ) { Optional optUser = userRepository.findById(id); - if(!optUser.isPresent()){ + if (!optUser.isPresent()) { request.setAttribute("error", "Der User wurde nicht gefunden."); response.setStatus(HttpServletResponse.SC_NOT_FOUND); return "error/404"; @@ -79,16 +83,16 @@ public class CustomersIndexController { @PostMapping("/{id}/changeState") public String changeState(@PathVariable("id") Long id, @RequestParam(value = "active", required = false) String active, - @RequestParam(value = "ma",required = false) String ma - ){ + @RequestParam(value = "ma", required = false) String ma + ) { User user = userRepository.findById(id).get(); - if(active == null) + if (active == null) user.isActive = false; else user.isActive = true; - if(ma == null) + if (ma == null) user.isEmployee = false; else user.isEmployee = true; @@ -103,13 +107,13 @@ public class CustomersIndexController { @RequestParam("password") String password, @RequestParam("password2") String password2, HttpServletRequest request - ){ - if(!password.equals(password2)){ + ) { + if (!password.equals(password2)) { request.setAttribute("error", "Passwörter stimmen nicht überein!"); return "/intern/customers/id"; } User user = userRepository.findById(id).get(); - if(!user.validatePassword(password)){ + if (!user.validatePassword(password)) { request.setAttribute("error", "Die Passwörter stimmen nicht mit dem Original überein!"); return "/intern/customers/id"; }