This repository has been archived on 2020-08-02. You can view files and clone it, but cannot push or open issues or pull requests.
e-commerce/web_backend/src/main/java/org/hso/ecommerce/controller/intern/customers/CustomerOrderController.java

72 lines
2.6 KiB
Java
Raw Normal View History

2020-04-29 22:44:16 +02:00
package org.hso.ecommerce.controller.intern.customers;
2020-04-28 22:41:29 +02:00
import org.hso.ecommerce.action.user.CreateDeliveryData;
2020-06-10 17:03:59 +02:00
import org.hso.ecommerce.api.RestServiceForDelivery;
2020-06-01 11:31:12 +02:00
import org.hso.ecommerce.entities.shop.CustomerOrder;
import org.hso.ecommerce.repos.shop.CustomerOrderRepository;
2020-06-17 17:23:29 +02:00
import org.hso.ecommerce.uimodel.DeliveryData;
2020-06-01 11:31:12 +02:00
import org.springframework.beans.factory.annotation.Autowired;
2020-04-28 22:41:29 +02:00
import org.springframework.stereotype.Controller;
2020-06-01 11:31:12 +02:00
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
2020-06-01 11:53:29 +02:00
import org.springframework.web.bind.annotation.PathVariable;
2020-06-01 11:31:12 +02:00
import org.springframework.web.bind.annotation.RequestMapping;
import java.util.List;
2020-06-10 14:51:12 +02:00
import java.util.stream.Collectors;
2020-04-28 22:41:29 +02:00
@Controller
2020-06-01 11:31:12 +02:00
@RequestMapping("intern/customerOrders")
2020-05-01 10:48:12 +02:00
public class CustomerOrderController {
2020-06-01 11:31:12 +02:00
@Autowired
private final CustomerOrderRepository customerOrderRepository = null;
2020-06-10 17:03:59 +02:00
@Autowired
private final RestServiceForDelivery restServiceForDelivery = null;
2020-06-01 11:31:12 +02:00
@GetMapping("")
public String internCustomerOrder(Model model) {
List<CustomerOrder> orders = customerOrderRepository.getAllOrders();
2020-06-10 14:51:12 +02:00
List<CustomerOrderDelivery> customerOrderDeliveryDataMap = orders
.stream()
.map(o -> new CustomerOrderDelivery(o, CreateDeliveryData.getDeliveryDataFromCustomerOrder(o, customerOrderRepository, restServiceForDelivery)))
.collect(Collectors.toList());
2020-06-10 14:51:12 +02:00
model.addAttribute("orderDeliveryDataMap", customerOrderDeliveryDataMap);
2020-06-01 11:31:12 +02:00
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;
}
}
2020-06-01 11:31:12 +02:00
@GetMapping("/{id}")
2020-06-01 11:53:29 +02:00
public String internCustomerOrdersId(Model model,
@PathVariable("id") String id
) {
CustomerOrder order = customerOrderRepository.findById(Long.parseLong(id)).get();
DeliveryData deliveryData = CreateDeliveryData.getDeliveryDataFromCustomerOrder(order, customerOrderRepository, restServiceForDelivery);
2020-06-01 11:53:29 +02:00
model.addAttribute("order", order);
2020-06-10 14:51:12 +02:00
model.addAttribute("deliveryData", deliveryData);
2020-06-01 11:53:29 +02:00
2020-06-01 11:31:12 +02:00
return "intern/customerOrders/id";
}
2020-04-28 22:41:29 +02:00
}