@RequestMapping(value = "/pizzeriaPizzaManager", method = RequestMethod.GET) public String pizzeriaPizzaManager(Model model, HttpSession session) { if (!SessionUtils.isPizzeria(session)) { return "homeLogInError"; } else { PizzaDAO pizzaDAO = (PizzaDAO) context.getBean("pizzaDAO"); List<Pizza> pizzas = pizzaDAO.getAll(); model.addAttribute("pizzas", pizzas); model.addAttribute("sizes", PizzaSize.values()); return "pizzeriaPizzaManager"; } }
@ResponseBody @RequestMapping(value = "/pizzeria/pizza", method = RequestMethod.POST) public String handleRequest(HttpSession session, @ModelAttribute PizzeriaPizzaForm form) { if (!SessionUtils.isPizzeria(session)) { return null; } PizzeriaDAO pizzeriaDAO = (PizzeriaDAO) context.getBean("pizzeriaDAO"); Pizzeria pizzeria = pizzeriaDAO.get(SessionUtils.getPizzeriaIdFromSessionOrNull(session)); PizzaDAO pizzaDAO = (PizzaDAO) context.getBean("pizzaDAO"); Pizza pizza = pizzaDAO.get(form.getPizzaId()); switch (form.getAction()) { case "add": return addPizza(pizzeria, pizza, form); case "update": return updatePizza(pizzeria, pizza, form); case "delete": return deletePizza(pizzeria, pizza, form); } return buildErrorResponse(); }