47 lines
1.7 KiB
Java
47 lines
1.7 KiB
Java
package org.hso.ecommerce.controller.intern.customers;
|
|
|
|
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.hso.ecommerce.entities.booking.Booking;
|
|
import org.hso.ecommerce.repos.booking.BookingRepository;
|
|
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;
|
|
|
|
@Controller
|
|
@RequestMapping("/intern/customers")
|
|
public class CustomersIndexController {
|
|
|
|
@Autowired
|
|
private BookingRepository bookingRepository = null;
|
|
|
|
@Autowired
|
|
private AccountingController accountingController = null;
|
|
|
|
@GetMapping("/")
|
|
public String internCustomers() {
|
|
return "intern/customers/index";
|
|
}
|
|
|
|
@GetMapping("/{customerId}")
|
|
public String internCustomersId(HttpServletRequest request, @PathVariable(required = true) long customerId) {
|
|
|
|
// Table of bookings
|
|
List<Booking> 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);
|
|
|
|
return "intern/customers/id";
|
|
}
|
|
|
|
}
|