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 de6fe66..a665533 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 @@ -1,20 +1,22 @@ package org.hso.ecommerce.controller.intern.customers; -import java.util.List; - -import javax.servlet.http.HttpServletRequest; - -import org.hso.ecommerce.controller.intern.AccountingController; -import org.hso.ecommerce.controller.intern.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 org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestMapping; +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 @RequestMapping("/intern/customers") @@ -24,25 +26,64 @@ public class CustomersIndexController { private BookingRepository bookingRepository = null; @Autowired - private AccountingController accountingController = null; + private final CustomerOrderRepository customerOrderRepository = null; + + @GetMapping("") + public String internCustomers(Model model) { @GetMapping("/") public String internCustomers() { return "intern/customers/index"; } - @GetMapping("/{customerId}") - public String internCustomersId(HttpServletRequest request, @PathVariable(required = true) long customerId) { + @GetMapping("/{id}") + public String internCustomersId(Model model, + @PathVariable("id") Long id, + HttpServletResponse response, + HttpServletRequest request + ) { + Optional optUser = userRepository.findById(id); + if(!optUser.isPresent()){ + request.setAttribute("error", "Der User wurde nicht gefunden."); + response.setStatus(HttpServletResponse.SC_NOT_FOUND); + return "error/404"; + } + User user = optUser.get(); + model.addAttribute("user", user); - // Table of bookings - List bookings = bookingRepository.customerBookingsReverseChronologically(customerId); - ShortTemplateBookingResult result = accountingController.buildShortTemplate( - bookings, - account -> account.userAccount != null && account.userAccount.id == customerId); - request.setAttribute("balance", result.balance); - request.setAttribute("bookings", result.bookings); + List orders = customerOrderRepository.getOrdersByUserId(id); + model.addAttribute("orders", orders); + + //TODO: Booking!!!!!!!!!!!! return "intern/customers/id"; } + @PostMapping("/{id}/changeState") + public String changeState(@PathVariable("id") Long id, + @RequestParam("active") Boolean active, + @RequestParam("ma") Boolean ma + ){ + System.out.println(id); + System.out.println(active); + System.out.println(ma); + + //TODO: Implement this!! + + return "/intern/customers/id"; + } + + @PostMapping("/{id}/resetPassword") + public String resetPassword(@PathVariable("id") Long id, + @RequestParam("password") String password, + @RequestParam("password2") String password2 + ){ + System.out.println(id); + System.out.println(password); + System.out.println(password2); + + //TODO: Implement this!! + + return "/intern/customers/id"; + } } diff --git a/prototype/src/main/resources/templates/intern/customers/id.html b/prototype/src/main/resources/templates/intern/customers/id.html index 4b41c22..e8aa609 100644 --- a/prototype/src/main/resources/templates/intern/customers/id.html +++ b/prototype/src/main/resources/templates/intern/customers/id.html @@ -23,7 +23,7 @@