Merge pull request 'feature/customers' (#58) from feature/customers into master
Reviewed-by: Jannik Seiler <seil0@mosad.xyz>
This commit is contained in:
commit
16803d2b12
|
@ -7,12 +7,19 @@ import javax.servlet.http.HttpServletRequest;
|
||||||
import org.hso.ecommerce.controller.intern.accounting.AccountingController;
|
import org.hso.ecommerce.controller.intern.accounting.AccountingController;
|
||||||
import org.hso.ecommerce.controller.intern.accounting.AccountingController.ShortTemplateBookingResult;
|
import org.hso.ecommerce.controller.intern.accounting.AccountingController.ShortTemplateBookingResult;
|
||||||
import org.hso.ecommerce.entities.booking.Booking;
|
import org.hso.ecommerce.entities.booking.Booking;
|
||||||
|
import org.hso.ecommerce.entities.shop.CustomerOrder;
|
||||||
|
import org.hso.ecommerce.entities.user.User;
|
||||||
import org.hso.ecommerce.repos.booking.BookingRepository;
|
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.beans.factory.annotation.Autowired;
|
||||||
|
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.ui.Model;
|
||||||
import org.springframework.web.bind.annotation.PathVariable;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
@Controller
|
@Controller
|
||||||
@RequestMapping("/intern/customers")
|
@RequestMapping("/intern/customers")
|
||||||
|
@ -21,26 +28,93 @@ public class CustomersIndexController {
|
||||||
@Autowired
|
@Autowired
|
||||||
private BookingRepository bookingRepository = null;
|
private BookingRepository bookingRepository = null;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private final CustomerOrderRepository customerOrderRepository = null;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private final UserRepository userRepository = null;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private AccountingController accountingController = null;
|
private AccountingController accountingController = null;
|
||||||
|
|
||||||
@GetMapping("/")
|
@GetMapping("")
|
||||||
public String internCustomers() {
|
public String internCustomers(Model model) {
|
||||||
|
List<User> users = userRepository.findAll();
|
||||||
|
|
||||||
|
model.addAttribute("users", users);
|
||||||
|
|
||||||
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(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<CustomerOrder> orders = customerOrderRepository.getOrdersByUserId(id);
|
||||||
List<Booking> bookings = bookingRepository.customerBookingsReverseChronologically(customerId);
|
model.addAttribute("orders", orders);
|
||||||
|
|
||||||
|
List<Booking> bookings = bookingRepository.customerBookingsReverseChronologically(id);
|
||||||
ShortTemplateBookingResult result = accountingController.buildShortTemplate(
|
ShortTemplateBookingResult result = accountingController.buildShortTemplate(
|
||||||
bookings,
|
bookings,
|
||||||
account -> account.userAccount != null && account.userAccount.id == customerId);
|
account -> account.userAccount != null && account.userAccount.id == id);
|
||||||
request.setAttribute("balance", result.balance);
|
model.addAttribute("balance", result.balance);
|
||||||
request.setAttribute("bookings", result.bookings);
|
model.addAttribute("bookings", result.bookings);
|
||||||
|
|
||||||
return "intern/customers/id";
|
return "intern/customers/id";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PostMapping("/{id}/changeState")
|
||||||
|
public String changeState(@PathVariable("id") Long id,
|
||||||
|
@RequestParam(value = "active", required = false) String active,
|
||||||
|
@RequestParam(value = "ma", required = false) String ma
|
||||||
|
) {
|
||||||
|
User user = userRepository.findById(id).get();
|
||||||
|
|
||||||
|
if (active == null)
|
||||||
|
user.isActive = false;
|
||||||
|
else
|
||||||
|
user.isActive = true;
|
||||||
|
|
||||||
|
if (ma == null)
|
||||||
|
user.isEmployee = false;
|
||||||
|
else
|
||||||
|
user.isEmployee = true;
|
||||||
|
|
||||||
|
userRepository.save(user);
|
||||||
|
|
||||||
|
return "redirect:/intern/customers/" + id.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/{id}/resetPassword")
|
||||||
|
public String resetPassword(@PathVariable("id") Long id,
|
||||||
|
@RequestParam("password") String password,
|
||||||
|
@RequestParam("password2") String password2,
|
||||||
|
HttpServletRequest request
|
||||||
|
) {
|
||||||
|
if (!password.equals(password2)) {
|
||||||
|
request.setAttribute("error", "Passwörter stimmen nicht überein!");
|
||||||
|
return "/intern/customers/id";
|
||||||
|
}
|
||||||
|
User user = userRepository.findById(id).get();
|
||||||
|
if (!user.validatePassword(password)) {
|
||||||
|
request.setAttribute("error", "Die Passwörter stimmen nicht mit dem Original überein!");
|
||||||
|
return "/intern/customers/id";
|
||||||
|
}
|
||||||
|
user.setPassword("12345");
|
||||||
|
userRepository.save(user);
|
||||||
|
request.setAttribute("info", "Passwort wurde auf 12345 geändert!");
|
||||||
|
|
||||||
|
return "/intern/customers/id";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,7 @@
|
||||||
<div class="sidebar-layout content-width">
|
<div class="sidebar-layout content-width">
|
||||||
<nav></nav>
|
<nav></nav>
|
||||||
<div>
|
<div>
|
||||||
<h1>Kunde 1510</h1>
|
<h1 th:text="|Kunde ${user.id}"></h1>
|
||||||
|
|
||||||
<script th:src="@{/js/back.js}"></script>
|
<script th:src="@{/js/back.js}"></script>
|
||||||
<div class="back" data-group="intern" data-insert="true"></div>
|
<div class="back" data-group="intern" data-insert="true"></div>
|
||||||
|
@ -37,33 +37,26 @@
|
||||||
<table class="key-value">
|
<table class="key-value">
|
||||||
<tr>
|
<tr>
|
||||||
<th>Nutzer</th>
|
<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>
|
||||||
<tr>
|
|
||||||
<th>Bonuspunktestand</th>
|
|
||||||
<td>50</td>
|
|
||||||
</tr>
|
|
||||||
|
|
||||||
<tr>
|
<tr>
|
||||||
<th>Name</th>
|
<th>Name</th>
|
||||||
<td>Hans Maier</td>
|
<td th:text="${user.name}"></td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th>E-Mail</th>
|
<th>E-Mail</th>
|
||||||
<td>hans.maier@example.com</td>
|
<td th:text="${user.email}"></td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th>Status</th>
|
<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>
|
||||||
<tr>
|
<tr>
|
||||||
<th>Adresse</th>
|
<th>Adresse</th>
|
||||||
<td>
|
<td th:Text="${user.defaultDeliveryAddress}"></td>
|
||||||
Hans Maier <br/>
|
|
||||||
Hauptstraße 12<br/>
|
|
||||||
74880 Musterstadt<br/>
|
|
||||||
Deutschland <br/>
|
|
||||||
</td>
|
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
</p>
|
</p>
|
||||||
|
@ -74,15 +67,15 @@
|
||||||
<div id="add-actions" class="invisible info-box secondary hero">
|
<div id="add-actions" class="invisible info-box secondary hero">
|
||||||
<h2>Status bearbeiten</h2>
|
<h2>Status bearbeiten</h2>
|
||||||
<p>
|
<p>
|
||||||
<form>
|
<form method="POST" th:action="@{/intern/customers/{id}/changeState(id=${user.id})}">
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<input type="checkbox" name="activ" id="activ" checked>
|
<input type="checkbox" name="active" id="active" th:checked="${user.isActive}">
|
||||||
<label for="activ">Aktiv</label> <br/>
|
<label for="active">Aktiv</label> <br/>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
|
|
||||||
<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/>
|
<label for="ma">Mitarbeiter-Status</label> <br/>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
|
|
||||||
|
@ -94,7 +87,7 @@
|
||||||
</p>
|
</p>
|
||||||
<h2>Passwort zurücksetzen</h2>
|
<h2>Passwort zurücksetzen</h2>
|
||||||
<p>
|
<p>
|
||||||
<form>
|
<form method="POST" th:action="@{/intern/customers/{id}/resetPassword(id=${user.id})}">
|
||||||
<div>
|
<div>
|
||||||
<label for="password">Passwort</label>
|
<label for="password">Passwort</label>
|
||||||
<input class="full-width" type="password" name="password" placeholder="Passwort" id="password"
|
<input class="full-width" type="password" name="password" placeholder="Passwort" id="password"
|
||||||
|
@ -113,10 +106,8 @@
|
||||||
</button>
|
</button>
|
||||||
</form>
|
</form>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
<h2>Bestellungen</h2>
|
<h2>Bestellungen</h2>
|
||||||
<p>
|
<p>
|
||||||
<table id="main-table">
|
<table id="main-table">
|
||||||
|
@ -127,22 +118,16 @@
|
||||||
<th>Status</th>
|
<th>Status</th>
|
||||||
<th></th>
|
<th></th>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr th:each="order: ${orders}">
|
||||||
<td>440</td>
|
<td th:text="${order.id}"></td>
|
||||||
<td>2019-12-54</td>
|
<td th:text="${order.formatCreated()}"></td>
|
||||||
<td>10,13 EUR</td>
|
<td th:text="${#numbers.formatDecimal(order.totalGrossCent * 0.01, 1, 'POINT', 2, 'COMMA')}"></td>
|
||||||
<td>Zugestellt</td>
|
<td th:if="${order.deliveredAt == null}">In Zustellung</td>
|
||||||
<td><a th:href="@{/intern/customerOrders/48584}" class="button smaller">Details</a></td>
|
<td th:if="${order.deliveredAt != null}">Zugestellt</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>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<h2>Buchungen</h2>
|
<h2>Buchungen</h2>
|
||||||
<div>
|
<div>
|
||||||
<h4> Kontostand </h4>
|
<h4> Kontostand </h4>
|
||||||
|
|
|
@ -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>
|
||||||
|
|
Reference in New Issue