implement customers index

This commit is contained in:
Hannes Huber 2020-06-03 20:26:36 +02:00
parent 7f643987f3
commit 5691f0eeec
2 changed files with 24 additions and 105 deletions

View File

@ -1,46 +1,34 @@
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.hso.ecommerce.entities.user.User;
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.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import java.util.List;
@Controller
@RequestMapping("/intern/customers")
public class CustomersIndexController {
@Autowired
private BookingRepository bookingRepository = null;
private final UserRepository userRepository = null;
@Autowired
private AccountingController accountingController = null;
@GetMapping("")
public String internCustomers(Model model) {
List<User> users = userRepository.findAll();
model.addAttribute("users", users);
@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);
@GetMapping("/{id}")
public String internCustomersId() {
return "intern/customers/id";
}
}

View File

@ -39,85 +39,16 @@
<th>Status</th>
<th></th>
</tr>
<tr>
<td>1209</td>
<td>2019-11-10</td>
<td>Hans Maier</td>
<td>hans.maier@example.com</td>
<td>Geschäftskunde</td>
<td><a th:href="@{/intern/customers/4884}" class="button smaller">Details</a></td>
</tr>
<tr>
<td>1208</td>
<td>2019-11-10</td>
<td>Hans Maier</td>
<td>hans.maier@example.com</td>
<td>Inaktiv, Geschäftskunde</td>
<td><a th:href="@{/intern/customers/4884}" class="button smaller">Details</a></td>
</tr>
<tr>
<td>1207</td>
<td>2019-11-10</td>
<td>Hans Maier</td>
<td>hans.maier@example.com</td>
<td></td>
<td><a th:href="@{/intern/customers/4884}" class="button smaller">Details</a></td>
</tr>
<tr>
<td>1206</td>
<td>2019-11-10</td>
<td>Hans Maier</td>
<td>hans.maier@example.com</td>
<td></td>
<td><a th:href="@{/intern/customers/4884}" class="button smaller">Details</a></td>
</tr>
<tr>
<td>1205</td>
<td>2019-11-10</td>
<td>Hans Maier</td>
<td>hans.maier@example.com</td>
<td></td>
<td><a th:href="@{/intern/customers/4884}" class="button smaller">Details</a></td>
</tr>
<tr>
<td>1204</td>
<td>2019-11-10</td>
<td>Hans Maier</td>
<td>hans.maier@example.com</td>
<td></td>
<td><a th:href="@{/intern/customers/4884}" class="button smaller">Details</a></td>
</tr>
<tr>
<td>1203</td>
<td>2019-11-10</td>
<td>Hans Maier</td>
<td>hans.maier@example.com</td>
<td></td>
<td><a th:href="@{/intern/customers/4884}" class="button smaller">Details</a></td>
</tr>
<tr>
<td>1202</td>
<td>2019-11-10</td>
<td>Hans Maier</td>
<td>hans.maier@example.com</td>
<td></td>
<td><a th:href="@{/intern/customers/4884}" class="button smaller">Details</a></td>
</tr>
<tr>
<td>1201</td>
<td>2019-11-10</td>
<td>Hans Maier</td>
<td>hans.maier@example.com</td>
<td>Inaktiv, Mitarbeiter</td>
<td><a th:href="@{/intern/customers/4884}" class="button smaller">Details</a></td>
</tr>
<tr>
<td>1214</td>
<td>2019-11-10</td>
<td>Hans Maier</td>
<td>admin@example.com</td>
<td>Mitarbeiter</td>
<td><a th:href="@{/intern/customers/4884}" class="button smaller">Details</a></td>
<tr th:each="user: ${users}">
<td th:text="${user.id}"></td>
<td th:text="${user.created.toString().substring(0, 10)}"></td>
<td th:text="${user.name}"></td>
<td th:text="${user.email}"></td>
<td>
<span th:text="${user.isActive} ? 'Aktiv,' : 'Inaktiv,'"></span>
<span th:text="${user.isEmployee} ? 'Mitarbeiter' : 'Kunde'"></span>
</td>
<td><a th:href="@{/intern/customers/{id}(id = ${user.id})}" class="button smaller">Details</a></td>
</tr>
</table>
</p>