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;
|
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.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.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.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
@Controller
|
@Controller
|
||||||
@RequestMapping("/intern/customers")
|
@RequestMapping("/intern/customers")
|
||||||
@ -24,25 +26,64 @@ public class CustomersIndexController {
|
|||||||
private BookingRepository bookingRepository = null;
|
private BookingRepository bookingRepository = null;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private AccountingController accountingController = null;
|
private final CustomerOrderRepository customerOrderRepository = null;
|
||||||
|
|
||||||
|
@GetMapping("")
|
||||||
|
public String internCustomers(Model model) {
|
||||||
|
|
||||||
@GetMapping("/")
|
@GetMapping("/")
|
||||||
public String internCustomers() {
|
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(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);
|
||||||
ShortTemplateBookingResult result = accountingController.buildShortTemplate(
|
|
||||||
bookings,
|
//TODO: Booking!!!!!!!!!!!!
|
||||||
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";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@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">
|
<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"
|
||||||
@ -127,19 +120,12 @@
|
|||||||
<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>
|
||||||
|
Reference in New Issue
Block a user