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; package org.hso.ecommerce.controller.intern.customers;
import java.util.List; import org.hso.ecommerce.entities.user.User;
import org.hso.ecommerce.repos.user.UserRepository;
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.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import java.util.List;
@Controller @Controller
@RequestMapping("/intern/customers") @RequestMapping("/intern/customers")
public class CustomersIndexController { public class CustomersIndexController {
@Autowired @Autowired
private BookingRepository bookingRepository = null; private final UserRepository userRepository = null;
@Autowired @GetMapping("")
private AccountingController accountingController = null; public String internCustomers(Model model) {
List<User> users = userRepository.findAll();
model.addAttribute("users", users);
@GetMapping("/")
public String internCustomers() {
return "intern/customers/index"; return "intern/customers/index";
} }
@GetMapping("/{customerId}") @GetMapping("/{id}")
public String internCustomersId(HttpServletRequest request, @PathVariable(required = true) long customerId) { public String internCustomersId() {
// 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"; return "intern/customers/id";
} }
} }

View File

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