package pl.codepot.aggregatr.aggregation.ingredient;

import com.google.common.collect.Lists;
import org.springframework.http.MediaType;
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 java.util.List;

/**
 * @author dchojnacki
 */
@RestController
@RequestMapping(value = "/ingredients", consumes = "application/vnd.pl.codepot.aggregatr.v1+json",
        produces = MediaType.APPLICATION_JSON_VALUE)
public class IngredientController {

    @RequestMapping(method = RequestMethod.POST)
    public Ingredients getIngredients(@RequestBody Order order) {
        List<Ingredient> result = Lists.newArrayList();
        for(IngredientType type : order.getItems()){
            result.add(new Ingredient(type.name(), 200));
        }
        return new Ingredients(result);
    }

}

@@ -51,48 +51,8 @@
 t;%0A%0A
-import com.google.common.collect.Lists;%0A
 impo
@@ -90,16 +90,16 @@
 iaType;%0A
+
 import o
@@ -356,20 +356,33 @@
 va.util.
-Li
 st
+ream.Collectors
 ;%0A%0A/**%0A 
@@ -738,132 +738,67 @@
     
-List%3CIngredient%3E result = Lists.newArrayList();%0A        for(IngredientType type : order.getItems())%7B%0A            result.add(
+return new Ingredients(order.getItems().stream().map(item-%3E
 new 
@@ -812,12 +812,12 @@
 ent(
-type
+item
 .nam
@@ -830,57 +830,37 @@
 00))
-;%0A        %7D%0A        return new Ingredients(result
+.collect(Collectors.toList())
 );%0A 

refactored to functional