This repository has been archived on 2020-08-02. You can view files and clone it, but cannot push or open issues or pull requests.
e-commerce/prototype/src/main/java/org/hso/ecommerce/controller/intern/customers/CustomersIndexController.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";
}
}