Пример #1
0
 @Override
 public JSONObject getRestaurantsById(String businessId, boolean isVisited) {
   try {
     String sql = "SELECT * from restaurants where business_id = ?";
     PreparedStatement statement = conn.prepareStatement(sql);
     statement.setString(1, businessId);
     ResultSet rs = statement.executeQuery();
     if (rs.next()) {
       Restaurant restaurant =
           new Restaurant(
               rs.getString("business_id"),
               rs.getString("name"),
               rs.getString("categories"),
               rs.getString("city"),
               rs.getString("state"),
               rs.getString("full_address"),
               rs.getFloat("stars"),
               rs.getFloat("latitude"),
               rs.getFloat("longitude"),
               rs.getString("image_url"),
               rs.getString("url"));
       JSONObject obj = restaurant.toJSONObject();
       obj.put("is_visited", isVisited);
       return obj;
     }
   } catch (Exception e) {
     /* report an error */
     System.out.println(e.getMessage());
   }
   return null;
 }
  public Restaurant updateRestaurant(long idresto, Restaurant restaurant) {
    ContentValues values = new ContentValues();

    values.put(MySQLiteHelperResto.COLUMN_NOM, restaurant.getNom());
    values.put(MySQLiteHelperResto.COLUMN_longitude, restaurant.getLongitude());
    values.put(MySQLiteHelperResto.COLUMN_latitude, restaurant.getLatitude());
    values.put(MySQLiteHelperResto.COLUMN_description, restaurant.getDescription());
    values.put(MySQLiteHelperResto.COLUMN_email, restaurant.getEmail());
    values.put(MySQLiteHelperResto.COLUMNhorairehouverture, restaurant.getHorairehouverture());
    values.put(MySQLiteHelperResto.COLUMN_horairefermeture, restaurant.getHorairefermeture());
    values.put(MySQLiteHelperResto.COLUMN_siteweb, restaurant.getSiteweb());
    values.put(MySQLiteHelperResto.COLUMN_image, restaurant.getImage());
    values.put(MySQLiteHelperResto.COLUMN_telephone, restaurant.getTelephone());
    values.put(MySQLiteHelperResto.COLUMN_ville, restaurant.getVille());
    values.put(MySQLiteHelperResto.COLUMN_pays, restaurant.getPays());

    database.update(
        MySQLiteHelperResto.TABLE_Restaurant,
        values,
        MySQLiteHelperResto.COLUMN_ID + " = " + restaurant.getIdresto(),
        null);

    return getRestaurantWithId(restaurant.getIdresto());
  }
 private Restaurant cursorTorestaurant(Cursor cursor) {
   Restaurant restaurant = new Restaurant();
   restaurant.setIdresto(cursor.getLong(0));
   restaurant.setNom(cursor.getString(1));
   restaurant.setLongitude(cursor.getString(2));
   restaurant.setLatitude(cursor.getString(3));
   restaurant.setDescription(cursor.getString(4));
   restaurant.setEmail(cursor.getString(5));
   restaurant.setHorairehouverture(cursor.getString(6));
   restaurant.setHorairefermeture(cursor.getString(7));
   restaurant.setSiteweb(cursor.getString(8));
   restaurant.setImage(cursor.getString(9));
   restaurant.setTelephone(cursor.getString(10));
   restaurant.setVille(cursor.getString(11));
   restaurant.setPays(cursor.getString(12));
   return restaurant;
 }
 public void deleteRestaurant(Restaurant restaurant) {
   long id = restaurant.getIdresto();
   System.out.println("Restaurant deleted with id: " + id);
   database.delete(
       MySQLiteHelperResto.TABLE_Restaurant, MySQLiteHelperResto.COLUMN_ID + " = " + id, null);
 }
Пример #5
0
  @Override
  public JSONArray searchRestaurants(String userId, double lat, double lon) {
    try {
      YelpAPI api = new YelpAPI();
      JSONObject response = new JSONObject(api.searchForBusinessesByLocation(lat, lon));
      JSONArray array = (JSONArray) response.get("businesses");

      List<JSONObject> list = new ArrayList<JSONObject>();
      Set<String> visited = getVisitedRestaurants(userId);

      for (int i = 0; i < array.length(); i++) {
        JSONObject object = array.getJSONObject(i);
        Restaurant restaurant = new Restaurant(object);
        String businessId = restaurant.getBusinessId();
        String name = restaurant.getName();
        String categories = restaurant.getCategories();
        String city = restaurant.getCity();
        String state = restaurant.getState();
        String fullAddress = restaurant.getFullAddress();
        double stars = restaurant.getStars();
        double latitude = restaurant.getLatitude();
        double longitude = restaurant.getLongitude();
        String imageUrl = restaurant.getImageUrl();
        String url = restaurant.getUrl();
        JSONObject obj = restaurant.toJSONObject();
        if (visited.contains(businessId)) {
          object.put("is_visited", true);
        } else {
          object.put("is_visited", false);
        }
        String sql = "INSERT IGNORE INTO restaurants VALUES (?,?,?,?,?,?,?,?,?,?,?)";
        PreparedStatement statement = conn.prepareStatement(sql);
        statement.setString(1, businessId);
        statement.setString(2, name);
        statement.setString(3, categories);
        statement.setString(4, city);
        statement.setString(5, state);
        statement.setDouble(6, stars);
        statement.setString(7, fullAddress);
        statement.setDouble(8, latitude);
        statement.setDouble(9, longitude);
        statement.setString(10, imageUrl);
        statement.setString(11, url);
        statement.execute();
        list.add(obj);
      }
      return new JSONArray(list);
    } catch (Exception e) {
      System.out.println(e.getMessage());
    }
    return null;
  }