コード例 #1
0
  @RequestMapping(value = "/pizzeria/pizzasList", method = RequestMethod.GET)
  public @ResponseBody List<RelationPizzeriaPizza> getPizzas(HttpSession session) {
    /*
     * If the author of the request is not logged in as a pizzeria, negate
     * the information.
     */
    if (!SessionUtils.isPizzeria(session)) {
      return null;
    }

    PizzeriaDAO pizzeriaDAO = (PizzeriaDAO) context.getBean("pizzeriaDAO");
    Pizzeria pizzeria = pizzeriaDAO.get(SessionUtils.getPizzeriaIdFromSessionOrNull(session));

    return pizzeria.getAvailablePizzasPriceList();
  }
コード例 #2
0
  @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();
  }