package com.nick;

import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * Created by dreamcatchernick on 25/09/2017.
 */
@RestController
public class OrderController {

    private List<Order> orders;
    public OrderController() {
        orders = new ArrayList<>();
        orders.add(new Order(1, 1 ,21.99, "This is Nick's order" , new Date()));
        orders.add(new Order(2, 2 ,0.99, "This is Mark's order" , new Date()));
        orders.add(new Order(3, 3 ,5.00, "This is John's order" , new Date()));
        orders.add(new Order(4, 4 ,100.00, "This is Bill's order" , new Date()));
        orders.add(new Order(5, 5 ,88.11, "This is Steve's order" , new Date()));
    }

    @RequestMapping(method = RequestMethod.GET, value = "/orders")
    public List<Order> getAllOrders() {
        return orders;
    }

    @RequestMapping(method = RequestMethod.GET, value = "/orders/{id}")
    public Order getOrder(@PathVariable int id) {
        return orders.stream().filter(o -> o.getUserId()==id).findFirst().get();
    }
}

@@ -335,16 +335,52 @@
 il.List;
+%0Aimport java.util.stream.Collectors;
 %0A%0A/**%0A *
@@ -975,24 +975,185 @@
 w Date()));%0A
+        orders.add(new Order(6, 1 ,77.96, %22This is Nick's order%22 , new Date()));%0A        orders.add(new Order(7, 1 ,9.20, %22This is Nick's order%22 , new Date()));%0A
     %7D%0A%0A    @
@@ -1346,17 +1346,32 @@
 = %22/
+get
 orders
-/%7Bi
+byuserid/%7BuserI
 d%7D%22)
@@ -1382,21 +1382,27 @@
  public 
+List%3C
 Order
+%3E
  getOrde
@@ -1421,17 +1421,21 @@
 ble int 
-i
+userI
 d) %7B%0A   
@@ -1491,31 +1491,48 @@
 Id()
+ 
 ==
-id).findFirst().ge
+ userId).collect(Collectors.toLis
 t()
+)
 ;%0A  

order controller