public static List<Choco> getByIds(List<Long> ids) {

    StringBuffer strIds = new StringBuffer();
    Iterator<Long> IterIds = ids.iterator();

    strIds.append("(");
    while (IterIds.hasNext()) {
      Long id = IterIds.next();
      strIds.append(id);
      if (IterIds.hasNext()) strIds.append(",");
    }
    strIds.append(")");
    return find.where("id IN " + strIds).findList();
  }
Esempio n. 2
0
  /**
   * Method to create meal. Use Meal.create method from models.
   *
   * @return
   */
  @Security.Authenticated(RestaurantFilter.class)
  public static Result createMeal() {
    User u = Session.getCurrentUser(ctx());
    if (!u.role.equalsIgnoreCase("RESTAURANT")) {
      return ok(views.html.admin.wrong.render("Cannot create meal if you're not reastaurant! "));
    }

    String mealName = inputForm.bindFromRequest().field("name").value();
    String mealPrice = inputForm.bindFromRequest().field("price").value();
    String mealCategory = inputForm.bindFromRequest().field("category").value();
    String mealDescription = inputForm.bindFromRequest().field("description").value();

    mealPrice = mealPrice.replace(',', '.');
    Double price = Double.parseDouble(mealPrice);
    Restaurant currentUser = u.restaurant;

    if ((Meal.create(mealName, price, mealCategory, currentUser, mealDescription)) == true) {
      Meal m =
          findM
              .where()
              .eq("name", mealName)
              .eq("price", mealPrice)
              .eq("restaurant_id", u.restaurant.id)
              .findUnique();
      String userEmail = Session.getCurrentUser(ctx()).email;
      Logger.debug(m.name);
      session("email", userEmail);
      flash("successMeal", "Succesfully created meal!");
      Logger.info("Restaurant " + currentUser.name + " just created meal");
      return ok(
          views.html.restaurant.fileUploadMeal.render("", userEmail, m, Restaurant.all(), m.image));
      // return redirect("/restaurantOwner/" + userEmail);
    }
    Logger.error("Restaurant " + currentUser.name + " failed to create meal.");
    return TODO;
  }
 public static List<Choco> rows(int rowId, int nbElemByRow) {
   Logger.debug("ChocoServices rows : " + find.all().size());
   Page<Choco> chocos = find.where().findPagingList(nbElemByRow).getPage(rowId);
   return chocos.getList();
 }