feature/customers #58
@ -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.ShortTemplateBookingResult;
 | 
			
		||||
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.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.HttpServletResponse;
 | 
			
		||||
import java.util.Optional;
 | 
			
		||||
 | 
			
		||||
@Controller
 | 
			
		||||
@RequestMapping("/intern/customers")
 | 
			
		||||
@ -21,26 +28,93 @@ public class CustomersIndexController {
 | 
			
		||||
    @Autowired
 | 
			
		||||
    private BookingRepository bookingRepository = null;
 | 
			
		||||
 | 
			
		||||
    @Autowired
 | 
			
		||||
    private final CustomerOrderRepository customerOrderRepository = null;
 | 
			
		||||
 | 
			
		||||
    @Autowired
 | 
			
		||||
    private final UserRepository userRepository = null;
 | 
			
		||||
 | 
			
		||||
    @Autowired
 | 
			
		||||
    private AccountingController accountingController = null;
 | 
			
		||||
 | 
			
		||||
    @GetMapping("/")
 | 
			
		||||
    public String internCustomers() {
 | 
			
		||||
    @GetMapping("")
 | 
			
		||||
    public String internCustomers(Model model) {
 | 
			
		||||
| 
					
	
	
	
	
	
	
	
	 | 
			||||
        List<User> users = userRepository.findAll();
 | 
			
		||||
 | 
			
		||||
        model.addAttribute("users", users);
 | 
			
		||||
 | 
			
		||||
        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();
 | 
			
		||||
| 
					
	
	
	
	
	
	
	
	 
				
					
						Seil0
						commented  
			
		Das userRepository fehlt. Das userRepository fehlt. 
			
			
		
				
					
						hhuber
						commented  
			
		siehe  siehe 938d16301d 
			
			
		 | 
			||||
        model.addAttribute("user", user);
 | 
			
		||||
 | 
			
		||||
        // Table of bookings
 | 
			
		||||
        List<Booking> bookings = bookingRepository.customerBookingsReverseChronologically(customerId);
 | 
			
		||||
        List<CustomerOrder> orders = customerOrderRepository.getOrdersByUserId(id);
 | 
			
		||||
        model.addAttribute("orders", orders);
 | 
			
		||||
 | 
			
		||||
        List<Booking> bookings = bookingRepository.customerBookingsReverseChronologically(id);
 | 
			
		||||
        ShortTemplateBookingResult result = accountingController.buildShortTemplate(
 | 
			
		||||
                bookings,
 | 
			
		||||
                account -> account.userAccount != null && account.userAccount.id == customerId);
 | 
			
		||||
        request.setAttribute("balance", result.balance);
 | 
			
		||||
        request.setAttribute("bookings", result.bookings);
 | 
			
		||||
                account -> account.userAccount != null && account.userAccount.id == id);
 | 
			
		||||
        model.addAttribute("balance", result.balance);
 | 
			
		||||
        model.addAttribute("bookings", result.bookings);
 | 
			
		||||
 | 
			
		||||
        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">
 | 
			
		||||
    <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"
 | 
			
		||||
@ -113,10 +106,8 @@
 | 
			
		||||
                </button>
 | 
			
		||||
            </form>
 | 
			
		||||
            </p>
 | 
			
		||||
 | 
			
		||||
        </div>
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        <h2>Bestellungen</h2>
 | 
			
		||||
        <p>
 | 
			
		||||
        <table id="main-table">
 | 
			
		||||
@ -127,22 +118,16 @@
 | 
			
		||||
                <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>
 | 
			
		||||
 | 
			
		||||
        <h2>Buchungen</h2>
 | 
			
		||||
        <div>
 | 
			
		||||
            <h4> Kontostand </h4>
 | 
			
		||||
 | 
			
		||||
@ -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>
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user
	
Kommt Doppelt vor.
siehe
938d16301d