Merge pull request 'Fix showing CustomerOrder all CustomerOrders in my orders. fix displaying orders in random order' (#108) from feature/fix_show_orders into master
reviewed by Lukas
This commit is contained in:
commit
186db31b17
|
@ -3,7 +3,6 @@ package org.hso.ecommerce.controller;
|
||||||
import org.hso.ecommerce.action.user.CreateDeliveryData;
|
import org.hso.ecommerce.action.user.CreateDeliveryData;
|
||||||
import org.hso.ecommerce.action.user.UpdateUserSettingsAction;
|
import org.hso.ecommerce.action.user.UpdateUserSettingsAction;
|
||||||
import org.hso.ecommerce.api.RestServiceForDelivery;
|
import org.hso.ecommerce.api.RestServiceForDelivery;
|
||||||
import org.hso.ecommerce.entities.shop.Address;
|
|
||||||
import org.hso.ecommerce.entities.shop.CustomerOrder;
|
import org.hso.ecommerce.entities.shop.CustomerOrder;
|
||||||
import org.hso.ecommerce.entities.user.User;
|
import org.hso.ecommerce.entities.user.User;
|
||||||
import org.hso.ecommerce.repos.shop.CustomerOrderRepository;
|
import org.hso.ecommerce.repos.shop.CustomerOrderRepository;
|
||||||
|
@ -12,16 +11,11 @@ import org.hso.ecommerce.uimodel.DeliveryData;
|
||||||
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.ui.Model;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpSession;
|
import javax.servlet.http.HttpSession;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.function.Function;
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@Controller
|
@Controller
|
||||||
|
@ -44,32 +38,48 @@ public class UserController {
|
||||||
|
|
||||||
@GetMapping("/settings")
|
@GetMapping("/settings")
|
||||||
public String userSettings(Model model,
|
public String userSettings(Model model,
|
||||||
HttpSession session
|
@RequestAttribute("user") User user
|
||||||
) {
|
) {
|
||||||
long userId = (long) session.getAttribute("userId");
|
|
||||||
User user = userRepository.findById(userId).get();
|
|
||||||
if(user.defaultDeliveryAddress == null){
|
|
||||||
user.defaultDeliveryAddress = new Address();
|
|
||||||
}
|
|
||||||
model.addAttribute("user", user);
|
model.addAttribute("user", user);
|
||||||
|
|
||||||
return "user/settings";
|
return "user/settings";
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/orders/")
|
@GetMapping("/orders/")
|
||||||
public String userOrders(HttpSession session,
|
public String userOrders(
|
||||||
|
@RequestAttribute("user") User user,
|
||||||
Model model
|
Model model
|
||||||
) {
|
) {
|
||||||
List<CustomerOrder> orders = customerOrderRepository.getAllOrders();
|
List<CustomerOrder> orders = customerOrderRepository.getOrdersByUserId(user.id);
|
||||||
|
|
||||||
Map<CustomerOrder, DeliveryData> customerOrderDeliveryDataMap = orders.stream().
|
List<CustomerOrderDelivery> customerOrderDeliveryDataMap = orders
|
||||||
collect(Collectors.toMap(Function.identity(), c -> CreateDeliveryData.getDeliveryDataFromCustomerOrder(c, customerOrderRepository, restServiceForDelivery)));
|
.stream()
|
||||||
|
.map(o -> new CustomerOrderDelivery(o, CreateDeliveryData.getDeliveryDataFromCustomerOrder(o, customerOrderRepository, restServiceForDelivery)))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
model.addAttribute("orderDeliveryDataMap", customerOrderDeliveryDataMap);
|
model.addAttribute("orderDeliveryDataMap", customerOrderDeliveryDataMap);
|
||||||
|
|
||||||
return "user/orders/index";
|
return "user/orders/index";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static class CustomerOrderDelivery {
|
||||||
|
private CustomerOrder customerOrder;
|
||||||
|
private DeliveryData deliveryData;
|
||||||
|
|
||||||
|
public CustomerOrderDelivery(CustomerOrder customerOrder, DeliveryData deliveryData) {
|
||||||
|
this.customerOrder = customerOrder;
|
||||||
|
this.deliveryData = deliveryData;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CustomerOrder getCustomerOrder() {
|
||||||
|
return customerOrder;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DeliveryData getDeliveryData() {
|
||||||
|
return deliveryData;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@PostMapping("/settings/changeMail")
|
@PostMapping("/settings/changeMail")
|
||||||
public String changeMail(HttpSession session,
|
public String changeMail(HttpSession session,
|
||||||
@RequestParam("email") String email,
|
@RequestParam("email") String email,
|
||||||
|
|
|
@ -12,8 +12,7 @@ import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.PathVariable;
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.List;
|
||||||
import java.util.function.Function;
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@Controller
|
@Controller
|
||||||
|
@ -29,14 +28,34 @@ public class CustomerOrderController {
|
||||||
public String internCustomerOrder(Model model) {
|
public String internCustomerOrder(Model model) {
|
||||||
List<CustomerOrder> orders = customerOrderRepository.getAllOrders();
|
List<CustomerOrder> orders = customerOrderRepository.getAllOrders();
|
||||||
|
|
||||||
Map<CustomerOrder, DeliveryData> customerOrderDeliveryDataMap = orders.stream().collect
|
List<CustomerOrderDelivery> customerOrderDeliveryDataMap = orders
|
||||||
(Collectors.toMap
|
.stream()
|
||||||
(Function.identity(), c-> CreateDeliveryData.getDeliveryDataFromCustomerOrder(c,customerOrderRepository,restServiceForDelivery)));
|
.map(o -> new CustomerOrderDelivery(o, CreateDeliveryData.getDeliveryDataFromCustomerOrder(o, customerOrderRepository, restServiceForDelivery)))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
model.addAttribute("orderDeliveryDataMap", customerOrderDeliveryDataMap);
|
model.addAttribute("orderDeliveryDataMap", customerOrderDeliveryDataMap);
|
||||||
|
|
||||||
return "intern/customerOrders/index";
|
return "intern/customerOrders/index";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static class CustomerOrderDelivery {
|
||||||
|
private CustomerOrder customerOrder;
|
||||||
|
private DeliveryData deliveryData;
|
||||||
|
|
||||||
|
public CustomerOrderDelivery(CustomerOrder customerOrder, DeliveryData deliveryData) {
|
||||||
|
this.customerOrder = customerOrder;
|
||||||
|
this.deliveryData = deliveryData;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CustomerOrder getCustomerOrder() {
|
||||||
|
return customerOrder;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DeliveryData getDeliveryData() {
|
||||||
|
return deliveryData;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@GetMapping("/{id}")
|
@GetMapping("/{id}")
|
||||||
public String internCustomerOrdersId(Model model,
|
public String internCustomerOrdersId(Model model,
|
||||||
@PathVariable("id") String id
|
@PathVariable("id") String id
|
||||||
|
|
|
@ -41,14 +41,16 @@
|
||||||
<th></th>
|
<th></th>
|
||||||
</tr>
|
</tr>
|
||||||
<tr th:each="order: ${orderDeliveryDataMap}">
|
<tr th:each="order: ${orderDeliveryDataMap}">
|
||||||
<td><a th:href="@{/intern/customers/{id}(id=${order.getKey().customer.id})}" th:text="${order.getKey().customer.id}">101</a></td>
|
<td><a th:href="@{/intern/customers/{id}(id=${order.customerOrder.customer.id})}"
|
||||||
<td th:text="${order.getKey().id}"></td>
|
th:text="${order.customerOrder.customer.id}">101</a></td>
|
||||||
<td th:text="${order.getKey().created.toString().substring(0, 10)}"></td>
|
<td th:text="${order.customerOrder.id}"></td>
|
||||||
<td th:text="${#numbers.formatDecimal(order.getKey().totalGrossCent * 0.01, 1, 'POINT', 2, 'COMMA')}"></td>
|
<td th:text="${order.customerOrder.created.toString().substring(0, 10)}"></td>
|
||||||
<td th:if="${order.getValue().allOk()}"><span th:text="${order.getValue().getStatus()}" /></td>
|
<td th:text="${#numbers.formatDecimal(order.customerOrder.totalGrossCent * 0.01, 1, 'POINT', 2, 'COMMA')}"></td>
|
||||||
<td th:if="${order.getValue().noTrackingID()}">Bestellung wurde elektronisch angekündigt</td>
|
<td th:if="${order.deliveryData.allOk()}"><span th:text="${order.deliveryData.getStatus()}"/></td>
|
||||||
<td th:if="${order.getValue().noData()}">DHL-Server ist gerade nicht erreichbar</td>
|
<td th:if="${order.deliveryData.noTrackingID()}">Bestellung wurde elektronisch angekündigt</td>
|
||||||
<td><a th:href="@{/intern/customerOrders/{id}(id=${order.getKey().id})}" class="button smaller">Details</a></td>
|
<td th:if="${order.deliveryData.noData()}">DHL-Server ist gerade nicht erreichbar</td>
|
||||||
|
<td><a th:href="@{/intern/customerOrders/{id}(id=${order.customerOrder.id})}" class="button smaller">Details</a>
|
||||||
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
</p>
|
</p>
|
||||||
|
|
|
@ -29,23 +29,30 @@
|
||||||
<table class="key-value">
|
<table class="key-value">
|
||||||
<tr>
|
<tr>
|
||||||
<th>Lieferstatus</th>
|
<th>Lieferstatus</th>
|
||||||
<td th:if="${order.getValue().allOk()}"><span th:text="${order.getValue().getStatus()}" /></td>
|
<td th:if="${order.deliveryData.allOk()}"><span th:text="${order.deliveryData.getStatus()}"/>
|
||||||
<td th:if="${order.getValue().noTrackingID()}">Bestellung wurde elektronisch angekündigt</td>
|
</td>
|
||||||
<td th:if="${order.getValue().noData()}">DHL-Server ist gerade nicht erreichbar</td>
|
<td th:if="${order.deliveryData.noTrackingID()}">Bestellung wurde elektronisch angekündigt</td>
|
||||||
|
<td th:if="${order.deliveryData.noData()}">DHL-Server ist gerade nicht erreichbar</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td></td>
|
<td></td>
|
||||||
<td th:if="${order.getKey().deliveredAt == null && order.getKey().trackingId!=null && !order.getValue().noData()}">Vorraussichtliche Ankunft: <span th:text="${order.getValue().getEstimatedArrival()}" /></td>
|
<td th:if="${order.customerOrder.deliveredAt == null && order.customerOrder.trackingId!=null && !order.deliveryData.noData()}">
|
||||||
<td th:if="${order.getKey().deliveredAt == null && order.getKey().trackingId!=null && order.getValue().noData()}">Vorraussichtliche Ankunft: --:--:----</td>
|
Vorraussichtliche Ankunft: <span th:text="${order.deliveryData.getEstimatedArrival()}"/>
|
||||||
<td th:if="${order.getKey().deliveredAt != null && order.getKey().trackingId!=null}"><b>Angekommen</b> Ankunft: <span th:text="${order.getValue().getEstimatedArrival()}" /></td>
|
</td>
|
||||||
|
<td th:if="${order.customerOrder.deliveredAt == null && order.customerOrder.trackingId!=null && order.deliveryData.noData()}">
|
||||||
|
Vorraussichtliche Ankunft: --:--:----
|
||||||
|
</td>
|
||||||
|
<td th:if="${order.customerOrder.deliveredAt != null && order.customerOrder.trackingId!=null}">
|
||||||
|
<b>Angekommen</b> Ankunft: <span th:text="${order.deliveryData.getEstimatedArrival()}"/>
|
||||||
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th>Sendeverfolgungsnummer</th>
|
<th>Sendeverfolgungsnummer</th>
|
||||||
<td th:text="${order.getKey().trackingId!=null} ? ${order.getKey().trackingId} : 'Es wurde noch keine Sendungsnummer vergeben'"></td>
|
<td th:text="${order.customerOrder.trackingId!=null} ? ${order.customerOrder.trackingId} : 'Es wurde noch keine Sendungsnummer vergeben'"></td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th></th>
|
<th></th>
|
||||||
<td th:text="${order.getKey().destination.toString()}" />
|
<td th:text="${order.customerOrder.destination.toString()}"/>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
@ -56,9 +63,11 @@
|
||||||
<th>Menge</th>
|
<th>Menge</th>
|
||||||
<th>Preis (Brutto)</th>
|
<th>Preis (Brutto)</th>
|
||||||
</tr>
|
</tr>
|
||||||
<tr th:each="position: ${order.getKey().positions}">
|
<tr th:each="position: ${order.customerOrder.positions}">
|
||||||
<td><a th:href="@{/shop/articles/{id}(id = ${position.article.id})}"><img th:src="@{/shop/articles/{id}/image.jpg(id=${position.article.id})}" class="s"/></a></td>
|
<td><a th:href="@{/shop/articles/{id}(id = ${position.article.id})}"><img
|
||||||
<td><a th:href="@{/shop/articles/{id}(id = ${position.article.id})}" th:text="${position.article.title}" class="s"></a></td>
|
th:src="@{/shop/articles/{id}/image.jpg(id=${position.article.id})}" class="s"/></a></td>
|
||||||
|
<td><a th:href="@{/shop/articles/{id}(id = ${position.article.id})}"
|
||||||
|
th:text="${position.article.title}" class="s"></a></td>
|
||||||
<td th:text="${position.quantity}"/>
|
<td th:text="${position.quantity}"/>
|
||||||
<td th:text="${#numbers.formatDecimal(position.getSumPrice() * 0.01, 1, 'POINT', 2, 'COMMA')}"/>
|
<td th:text="${#numbers.formatDecimal(position.getSumPrice() * 0.01, 1, 'POINT', 2, 'COMMA')}"/>
|
||||||
</tr>
|
</tr>
|
||||||
|
@ -72,13 +81,13 @@
|
||||||
<td></td>
|
<td></td>
|
||||||
<td></td>
|
<td></td>
|
||||||
<td>Artikel (Netto)</td>
|
<td>Artikel (Netto)</td>
|
||||||
<td th:text="${#numbers.formatDecimal(order.getKey().totalNetCent * 0.01, 1, 'POINT', 2, 'COMMA')}" />
|
<td th:text="${#numbers.formatDecimal(order.customerOrder.totalNetCent * 0.01, 1, 'POINT', 2, 'COMMA')}"/>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td></td>
|
<td></td>
|
||||||
<td></td>
|
<td></td>
|
||||||
<td>Umsatzsteuer</td>
|
<td>Umsatzsteuer</td>
|
||||||
<td th:text="${#numbers.formatDecimal(order.getKey().totalVatCent * 0.01, 1, 'POINT', 2, 'COMMA')}" />
|
<td th:text="${#numbers.formatDecimal(order.customerOrder.totalVatCent * 0.01, 1, 'POINT', 2, 'COMMA')}"/>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td></td>
|
<td></td>
|
||||||
|
@ -87,7 +96,7 @@
|
||||||
<h3>Gesammtpreis</h3>
|
<h3>Gesammtpreis</h3>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<h3 th:text="${#numbers.formatDecimal(order.getKey().totalGrossCent * 0.01, 1, 'POINT', 2, 'COMMA')}"/>
|
<h3 th:text="${#numbers.formatDecimal(order.customerOrder.totalGrossCent * 0.01, 1, 'POINT', 2, 'COMMA')}"/>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
|
|
Reference in New Issue