implement customers detail part 1
This commit is contained in:
parent
28834431ce
commit
49e26039a3
|
@ -1,20 +1,22 @@
|
|||
package org.hso.ecommerce.controller.intern.customers;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.hso.ecommerce.controller.intern.AccountingController;
|
||||
import org.hso.ecommerce.controller.intern.AccountingController.ShortTemplateBookingResult;
|
||||
import org.hso.ecommerce.entities.booking.Booking;
|
||||
import org.hso.ecommerce.entities.booking.BookingAccountEntry;
|
||||
import org.hso.ecommerce.entities.shop.CustomerOrder;
|
||||
import org.hso.ecommerce.entities.user.User;
|
||||
import org.hso.ecommerce.repos.booking.BookingAccountEntryRepository;
|
||||
import org.hso.ecommerce.repos.booking.BookingRepository;
|
||||
import org.hso.ecommerce.repos.shop.CustomerOrderRepository;
|
||||
import org.hso.ecommerce.repos.user.UserRepository;
|
||||
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;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/intern/customers")
|
||||
|
@ -24,25 +26,64 @@ public class CustomersIndexController {
|
|||
private BookingRepository bookingRepository = null;
|
||||
|
||||
@Autowired
|
||||
private AccountingController accountingController = null;
|
||||
private final CustomerOrderRepository customerOrderRepository = null;
|
||||
|
||||
@GetMapping("")
|
||||
public String internCustomers(Model model) {
|
||||
|
||||
@GetMapping("/")
|
||||
public String internCustomers() {
|
||||
return "intern/customers/index";
|
||||
}
|
||||
|
||||
@GetMapping("/{customerId}")
|
||||
public String internCustomersId(HttpServletRequest request, @PathVariable(required = true) long customerId) {
|
||||
@GetMapping("/{id}")
|
||||
public String internCustomersId(Model model,
|
||||
@PathVariable("id") Long id,
|
||||
HttpServletResponse response,
|
||||
HttpServletRequest request
|
||||
) {
|
||||
Optional<User> optUser = userRepository.findById(id);
|
||||
if(!optUser.isPresent()){
|
||||
request.setAttribute("error", "Der User wurde nicht gefunden.");
|
||||
response.setStatus(HttpServletResponse.SC_NOT_FOUND);
|
||||
return "error/404";
|
||||
}
|
||||
User user = optUser.get();
|
||||
model.addAttribute("user", user);
|
||||
|
||||
// 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);
|
||||
List<CustomerOrder> orders = customerOrderRepository.getOrdersByUserId(id);
|
||||
model.addAttribute("orders", orders);
|
||||
|
||||
//TODO: Booking!!!!!!!!!!!!
|
||||
|
||||
return "intern/customers/id";
|
||||
}
|
||||
|
||||
@PostMapping("/{id}/changeState")
|
||||
public String changeState(@PathVariable("id") Long id,
|
||||
@RequestParam("active") Boolean active,
|
||||
@RequestParam("ma") Boolean ma
|
||||
){
|
||||
System.out.println(id);
|
||||
System.out.println(active);
|
||||
System.out.println(ma);
|
||||
|
||||
//TODO: Implement this!!
|
||||
|
||||
return "/intern/customers/id";
|
||||
}
|
||||
|
||||
@PostMapping("/{id}/resetPassword")
|
||||
public String resetPassword(@PathVariable("id") Long id,
|
||||
@RequestParam("password") String password,
|
||||
@RequestParam("password2") String password2
|
||||
){
|
||||
System.out.println(id);
|
||||
System.out.println(password);
|
||||
System.out.println(password2);
|
||||
|
||||
//TODO: Implement this!!
|
||||
|
||||
return "/intern/customers/id";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
<div class="sidebar-layout content-width">
|
||||
<nav></nav>
|
||||
<div>
|
||||
<h1>Kunde 1510</h1>
|
||||
<h1 th:text="|Kunde ${user.id}"></h1>
|
||||
|
||||
<script th:src="@{/js/back.js}"></script>
|
||||
<div class="back" data-group="intern" data-insert="true"></div>
|
||||
|
@ -37,33 +37,26 @@
|
|||
<table class="key-value">
|
||||
<tr>
|
||||
<th>Nutzer</th>
|
||||
<td><a th:href="@{/intern/customers/498}">1510</a></td>
|
||||
<td><a th:href="@{/intern/customers/{id}(id=${user.id})}" th:text="${user.id}"></a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Bonuspunktestand</th>
|
||||
<td>50</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<td>Hans Maier</td>
|
||||
<td th:text="${user.name}"></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>E-Mail</th>
|
||||
<td>hans.maier@example.com</td>
|
||||
<td th:text="${user.email}"></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Status</th>
|
||||
<td>Geschäftskunde, Aktiv</td>
|
||||
<td>
|
||||
<span th:text="${user.isActive} ? 'Aktiv,' : 'Inaktiv,'"></span>
|
||||
<span th:text="${user.isEmployee} ? 'Mitarbeiter' : 'Kunde'"></span>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Adresse</th>
|
||||
<td>
|
||||
Hans Maier <br/>
|
||||
Hauptstraße 12<br/>
|
||||
74880 Musterstadt<br/>
|
||||
Deutschland <br/>
|
||||
</td>
|
||||
<td th:Text="${user.defaultDeliveryAddress}"></td>
|
||||
</tr>
|
||||
</table>
|
||||
</p>
|
||||
|
@ -74,15 +67,15 @@
|
|||
<div id="add-actions" class="invisible info-box secondary hero">
|
||||
<h2>Status bearbeiten</h2>
|
||||
<p>
|
||||
<form>
|
||||
<form method="POST" th:action="@{/intern/customers/{id}/changeState(id=${user.id})}">
|
||||
<fieldset>
|
||||
<input type="checkbox" name="activ" id="activ" checked>
|
||||
<label for="activ">Aktiv</label> <br/>
|
||||
<input type="checkbox" name="active" id="active" th:checked="${user.isActive}">
|
||||
<label for="active">Aktiv</label> <br/>
|
||||
</fieldset>
|
||||
|
||||
<fieldset>
|
||||
|
||||
<input type="checkbox" name="ma" id="ma">
|
||||
<input type="checkbox" name="ma" id="ma" th:checked="${user.isEmployee}">
|
||||
<label for="ma">Mitarbeiter-Status</label> <br/>
|
||||
</fieldset>
|
||||
|
||||
|
@ -94,7 +87,7 @@
|
|||
</p>
|
||||
<h2>Passwort zurücksetzen</h2>
|
||||
<p>
|
||||
<form>
|
||||
<form method="POST" th:action="@{/intern/customers/{id}/resetPassword(id=${user.id})}">
|
||||
<div>
|
||||
<label for="password">Passwort</label>
|
||||
<input class="full-width" type="password" name="password" placeholder="Passwort" id="password"
|
||||
|
@ -127,19 +120,12 @@
|
|||
<th>Status</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>440</td>
|
||||
<td>2019-12-54</td>
|
||||
<td>10,13 EUR</td>
|
||||
<td>Zugestellt</td>
|
||||
<td><a th:href="@{/intern/customerOrders/48584}" class="button smaller">Details</a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>241</td>
|
||||
<td>2019-11-10</td>
|
||||
<td>40,13 EUR</td>
|
||||
<td>In Zustellung</td>
|
||||
<td><a th:href="@{/intern/customerOrders/48584}" class="button smaller">Details</a></td>
|
||||
<tr th:each="order: ${orders}">
|
||||
<td th:text="${order.id}"></td>
|
||||
<td th:text="${order.formatCreated()}"></td>
|
||||
<td th:text="${#numbers.formatDecimal(order.totalGrossCent * 0.01, 1, 'POINT', 2, 'COMMA')}"></td>
|
||||
<td th:if="${order.deliveredAt == null}">In Zustellung</td>
|
||||
<td th:if="${order.deliveredAt != null}">Zugestellt</td>
|
||||
</tr>
|
||||
</table>
|
||||
</p>
|
||||
|
|
Reference in New Issue