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
Raw Normal View History

2020-04-29 22:44:16 +02:00
package org.hso.ecommerce.controller.intern.customers;
2020-04-28 22:41:29 +02:00
2020-06-05 07:49:11 +02:00
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;
2020-06-05 07:49:11 +02:00
import org.hso.ecommerce.entities.booking.Booking;
import org.hso.ecommerce.repos.booking.BookingRepository;
import org.springframework.beans.factory.annotation.Autowired;
2020-04-28 22:41:29 +02:00
import org.springframework.stereotype.Controller;
2020-06-05 07:49:11 +02:00
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
2020-04-28 22:41:29 +02:00
@Controller
2020-06-05 07:49:11 +02:00
@RequestMapping("/intern/customers")
2020-05-01 10:48:12 +02:00
public class CustomersIndexController {
2020-06-05 07:49:11 +02:00
@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";
}
2020-04-28 22:41:29 +02:00
}