package pl.konczak.microservices.web.rest;

import java.util.List;

import org.springframework.http.HttpEntity;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import pl.konczak.microservices.domain.IOrderBO;
import pl.konczak.microservices.domain.IOrderRepository;
import pl.konczak.microservices.domain.Order;

@RestController
@RequestMapping("/order")
public class OrderApi {

    private final IOrderRepository orderRepository;

    private final IOrderBO orderBO;

    public OrderApi(IOrderRepository orderRepository, IOrderBO orderBO) {
        this.orderRepository = orderRepository;
        this.orderBO = orderBO;
    }

    @RequestMapping(method = RequestMethod.GET)
    public List<Order> list() {
        return orderRepository.findAll();
    }

    @RequestMapping(method = RequestMethod.GET,
                    value = "/{id}")
    public HttpEntity<Order> get(@PathVariable("id") Long id) {
        Order order = orderRepository.getOne(id);

        if (order == null) {
            return ResponseEntity.badRequest().build();
        }

        return ResponseEntity.ok(order);
    }

    @RequestMapping(method = RequestMethod.POST)
    public HttpEntity<Order> order(@RequestBody OrderCreateCommand orderCreateCommand) {
        Order order = orderBO.create(orderCreateCommand.getCustomerId(), orderCreateCommand.getProductIds());
        return ResponseEntity.ok(order);
    }
}

@@ -57,24 +57,81 @@
 util.List;%0A%0A
+import org.slf4j.Logger;%0Aimport org.slf4j.LoggerFactory;%0A
 import org.s
@@ -154,32 +154,32 @@
 ttp.HttpEntity;%0A
-
 import org.sprin
@@ -740,16 +740,99 @@
 rApi %7B%0A%0A
+    private static final Logger LOGGER = LoggerFactory.getLogger(OrderApi.class);%0A%0A
     priv
@@ -1150,24 +1150,59 @@
 r%3E list() %7B%0A
+        LOGGER.info(%22GET /order%22);%0A
         retu
@@ -1383,24 +1383,66 @@
  Long id) %7B%0A
+        LOGGER.info(%22GET /order/%7B%7D%22, id);%0A
         Orde
@@ -1673,16 +1673,16 @@
 d.POST)%0A
-
     publ
@@ -1758,24 +1758,60 @@
 eCommand) %7B%0A
+        LOGGER.info(%22POST /order%22);%0A
         Orde

add missing logs in OrderApi