90 lines
2.9 KiB
Java
90 lines
2.9 KiB
Java
package org.hso.ecommerce.controller.intern.customers;
|
|
|
|
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.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")
|
|
public class CustomersIndexController {
|
|
|
|
@Autowired
|
|
private BookingRepository bookingRepository = null;
|
|
|
|
@Autowired
|
|
private final CustomerOrderRepository customerOrderRepository = null;
|
|
|
|
@GetMapping("")
|
|
public String internCustomers(Model model) {
|
|
|
|
@GetMapping("/")
|
|
public String internCustomers() {
|
|
return "intern/customers/index";
|
|
}
|
|
|
|
@GetMapping("/{id}")
|
|
public String internCustomersId(Model model,
|
|
@PathVariable("id") Long id,
|
|
HttpServletResponse response,
|
|
HttpServletRequest request
|
|
) {
|
|
Optional<User> 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);
|
|
|
|
List<CustomerOrder> 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";
|
|
}
|
|
}
|