private String deletePizza(Pizzeria pizzeria, Pizza pizza, PizzeriaPizzaForm form) { List<RelationPizzeriaPizza> pizzeriaPizzas = pizzeria.getPizzasPriceList(); /* * Only update the pizza if the pizzeria has already a * RelationPizzeriaPizza with the same id. */ for (RelationPizzeriaPizza pizzeriaPizza : pizzeriaPizzas) { if (pizzeriaPizza.getId() == form.getId()) { /* * FIXME - Prevent the elimination of RelationPizzeriaPizzas * which belong to an OrderItem which has not yet been * collected. */ RelationPizzeriaPizzaDAO dao = (RelationPizzeriaPizzaDAO) context.getBean("relationPizzeriaPizzaDAO"); pizzeriaPizza.setAvailable(false); dao.update(pizzeriaPizza); return buildOkResponse(pizzeriaPizza); } } return buildErrorResponse(); }
private String updatePizza(Pizzeria pizzeria, Pizza pizza, PizzeriaPizzaForm form) { List<RelationPizzeriaPizza> pizzeriaPizzas = pizzeria.getPizzasPriceList(); /* * Only update the pizza if the pizzeria has already a * RelationPizzeriaPizza with the same id. */ for (RelationPizzeriaPizza pizzeriaPizza : pizzeriaPizzas) { if (pizzeriaPizza.getId() == form.getId()) { pizzeriaPizza.setPizza(pizza); pizzeriaPizza.setPizzaSize(form.getSize()); pizzeriaPizza.setPreparationTime(form.getPreparationTimeInSeconds()); pizzeriaPizza.setGlutenFree(form.getGlutenFree()); pizzeriaPizza.setPrice(form.getPrice()); RelationPizzeriaPizzaDAO dao = (RelationPizzeriaPizzaDAO) context.getBean("relationPizzeriaPizzaDAO"); dao.update(pizzeriaPizza); return buildOkResponse(pizzeriaPizza); } } return buildErrorResponse(); }
private String addPizza(Pizzeria pizzeria, Pizza pizza, PizzeriaPizzaForm form) { RelationPizzeriaPizza pizzeriaPizza = new RelationPizzeriaPizza( pizzeria, pizza, form.getPrice(), form.getSize(), form.getPreparationTimeInSeconds(), form.getGlutenFree()); // FIXME - Validate data: user can't add an entry that already exists // (same data). RelationPizzeriaPizzaDAO dao = (RelationPizzeriaPizzaDAO) context.getBean("relationPizzeriaPizzaDAO"); dao.create(pizzeriaPizza); /* * Now the pizzeriaPizza object contains the id of the newly created * instance. */ return buildOkResponse(pizzeriaPizza); }