2020-04-29 22:44:16 +02:00
package org.hso.ecommerce.controller.intern.customers ;
2020-04-28 22:41:29 +02:00
2020-06-18 00:50:43 +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 ;
2020-06-13 19:58:30 +02:00
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 ;
2020-06-10 14:51:12 +02:00
import java.util.* ;
import java.util.function.Function ;
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
2020-06-13 19:58:30 +02:00
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
Map < CustomerOrder , DeliveryData > customerOrderDeliveryDataMap = orders . stream ( ) . collect
( Collectors . toMap
2020-06-18 00:50:43 +02:00
( Function . identity ( ) , c - > CreateDeliveryData . getDeliveryDataFromCustomerOrder ( c , customerOrderRepository , restServiceForDelivery ) ) ) ;
2020-06-10 14:51:12 +02:00
model . addAttribute ( " orderDeliveryDataMap " , customerOrderDeliveryDataMap ) ;
2020-06-01 11:31:12 +02:00
return " intern/customerOrders/index " ;
}
@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 ( ) ;
2020-06-18 00:50:43 +02:00
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
}