Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package tacoss.web;
- import lombok.extern.slf4j.Slf4j;
- import org.springframework.stereotype.Controller;
- import org.springframework.ui.Model;
- import org.springframework.web.bind.annotation.GetMapping;
- import org.springframework.web.bind.annotation.RequestMapping;
- import tacoss.Ingredient;
- import tacoss.Ingredient.Type;
- import tacoss.Taco;
- import java.util.Arrays;
- import java.util.List;
- import java.util.stream.Collectors;
- @Slf4j
- @Controller
- @RequestMapping(value = "/design")
- public class DesignTacoController {
- void addIngredientsToModel(Model model) {
- List<Ingredient> ingredients = Arrays.asList(
- new Ingredient("FLTO", "Flour Tortilla", Type.WRAP),
- new Ingredient("COTO", "Corn Tortilla", Type.WRAP),
- new Ingredient("GRBF", "Ground Beef", Type.PROTEIN),
- new Ingredient("CARN", "Carnitas", Type.PROTEIN),
- new Ingredient("TMTO", "Diced Tomatoes", Type.VEGGIES),
- new Ingredient("LETC", "Lettuce", Type.VEGGIES),
- new Ingredient("CHED", "Cheddar", Type.CHEESE),
- new Ingredient("JACK", "Monterrey Jack", Type.CHEESE),
- new Ingredient("SLSA", "Salsa", Type.SAUCE),
- new Ingredient("SRCR", "Sour Cream", Type.SAUCE)
- );
- Ingredient.Type[] types = Ingredient.Type.values();
- for (Ingredient.Type type : types) {
- model.addAttribute(type.toString().toLowerCase(),
- filterByType(ingredients, type));
- }
- }
- @GetMapping
- public String showDesignForm(Model model) {
- addIngredientsToModel(model);
- model.addAttribute("design", new Taco());
- return "design";
- }
- private List<Ingredient> filterByType(
- List<Ingredient> ingredients, Type type) {
- return ingredients
- .stream()
- .filter(x -> x.getType().equals(type))
- .collect(Collectors.toList());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement