Beispiel #1
0
def all_restaurants_handler():
    #YOUR CODE HERE
    if request.method == 'GET':
        restaurants = session.query(Restaurant).all()
        return jsonify(restaurants=[i.serialize for i in restaurants])

    elif request.method == 'POST':
        #location = request.args.get('location')
        #mealtype = request.args.get('mealType')
        location = 'Lima+Peru'
        mealtype = 'sushi'
        restaurant_info = findARestaurant(mealtype, location)
        if restaurant_info != 'No Restaurants Found':
            restaurant = Restaurant(
                restaurant_name=restaurant_info['name'],
                restaurant_address=restaurant_info['address'],
                restaurant_image=restaurant_info['image'])

            session.add(restaurant)
            session.commit()
            return jsonify(restaurant=restaurant.serialize)
        else:
            return jsonify({
                "error":
                "No restaurants found for %s and %s" % (location, mealtype)
            })
Beispiel #2
0
def Makerequest(id):
    user = session.query(User).filter_by(id=id).first()
    if request.method=='POST':
        location=request.form['location']
        if location=="" or request.form['meal_type']==""or request.form['date']=="" or request.form['time']=="":
           flash('this two input should not be empty')
           return render_template('RequestPage.html',user=user)
        latitude,longitude=getGeocodeLocation(location)
        if latitude=="zero":
           flash('Sorry,can not find your location')
           return render_template('RequestPage.html',user=user)
        restaurant_info=findARestaurant(request.form['meal_type'],location)
        if restaurant_info=="No Restaurants Found":
           flash('Sorry,can not find the target restaurant according your meal type')
           return render_template('RequestPage.html',user=user)
        meal_time=request.form['date']+request.form['time']
        Re=Request(user_id=id)
        Re.meal_type=request.form['meal_type']
        Re.latitude=latitude
        Re.longitude=longitude
        Re.location_string=location
        session.add(Re)
        session.commit()
        return render_template('RequestPage.html',user=user)
    else:
        return render_template('RequestPage.html',user=user)
def all_restaurants_handler():
	if request.method == 'GET':
		# RETURN ALL RESTAURANTS IN DATABASE
		restaurants = session.query(Restaurant).all()
		return jsonify(restaurants = [i.serialize for i in restaurants])

	elif request.method == 'POST':
		# MAKE A NEW RESTAURANT AND STORE IT IN DATABASE
		location = request.json['location']
		mealType = request.json['mealType']    
		restaurant_info = findARestaurant(mealType, location)
		r_message = {"message":"No Restaurants Found"}
		# Condition for taking the dictionary stored in the array and populating the fields in DB
		if restaurant_info[0] != r_message:
			for r in range(len(restaurant_info)):
				rest_data = restaurant_info[r]
				restaurant = Restaurant(**restaurant_info[r])
				session.add(restaurant)
				session.commit() 
			return jsonify(restaurant = restaurant_info)
		else:
			# Store parameters as a proper noun
			meal = mealType.capitalize()
			loc = location.capitalize()
			# Return error messages
			return jsonify({"Error":"No Restaurants Found for %s in %s" % (meal, loc)})
Beispiel #4
0
def all_restaurants_handler():
    if request.method == 'GET':
        restaurants = session.query(Restaurant).all()
        return jsonify(restaurants=[i.serialize for i in restaurants])

    elif request.method == 'POST':
        location = request.args.get('location', '')
        mealType = request.args.get('mealType', '')
        restaurant_info = findARestaurant(mealType, location)
        #        prints fail to work due to ascii unicode error
        #        print unicode(restaurant_info['name'])
        #        print unicode(restaurant_info['address'])
        #        print restaurant_info['image']
        if restaurant_info != 'No Restaurants Found':
            newRestaurant = Restaurant(
                restaurant_name=unicode(restaurant_info['name']),
                restaurant_address=unicode(restaurant_info['address']),
                restaurant_image=restaurant_info['image'])
            session.add(newRestaurant)
            session.commit()
            print 'New Restaurant added to database'
            return jsonify(newRestaurant=newRestaurant.serialize)
        else:
            return jsonify({
                "error":
                "No Restaurants Found for %s in %s" % (mealType, location)
            })
def all_restaurants_handler():
    if request.method == 'GET':
        # RETURN ALL RESTAURANTS IN DATABASE
        restaurants = session.query(Restaurant).all()
        return jsonify(restaurants=[i.serialize for i in restaurants])

    elif request.method == 'POST':
        # MAKE A NEW RESTAURANT AND STORE IT IN DATABASE
        location = request.args.get('location', '')
        mealType = request.args.get('mealType', '')
        print location
        print mealType
        restaurant_info = findARestaurant(mealType, location)
        if restaurant_info != "No Restaurants Found":
            restaurant = Restaurant(
                restaurant_name=unicode(restaurant_info['name']),
                restaurant_address=unicode(restaurant_info['address']),
                restaurant_image=restaurant_info['image'])
            session.add(restaurant)
            session.commit()
            return jsonify(restaurant=restaurant.serialize)
        else:
            return jsonify({
                "error":
                "No Restaurants Found for %s in %s" % (mealType, location)
            })
Beispiel #6
0
def all_restaurants_handler():
    # return "heck"
    print("i want to burn docker to the ground")
    if request.method == 'GET':
        restaurants = session.query(Restaurant).all()
        return jsonify(restaurants=[i.serialize for i in restaurants])

    elif request.method == 'POST':
        # print('code reaches here')
        print("POST\n")
        print(request.form)
        location = request.args.get('location', '')  #('location', '')
        mealType = request.args.get('mealType', '')
        # print(location, mealType)
        restaurantInfo = findARestaurant(mealType, location)
        if restaurantInfo != "No Restaurants Found":
            restaurant = Restaurant(
                restaurant_name=restaurantInfo['name'],
                restaurant_address=restaurantInfo['address'],
                restaurant_image=restaurantInfo['image'])
            session.add(restaurant)
            session.commit()
            return jsonify(restaurant=restaurant.serialize)
        else:
            return jsonify({
                "error":
                "No Restaurants Found for %s in %s" % (mealType, location)
            })
Beispiel #7
0
def all_restaurants_handler():
    if request.method == 'GET':
        restaurants = session.query(Restaurant).all()
        return jsonify(
            restaurants=[restaurant.serialize for restaurant in restaurants])
    elif request.method == 'POST':
        # get location and meal type from query
        location = request.args.get('location')
        mealType = request.args.get('mealType')
        # find restaurant based on location and meal Type
        restaurantInfo = findARestaurant(mealType, location)
        if restaurantInfo != "No Restaurants Found":
            # add this new restaurant in database
            restaurant = Restaurant(
                restaurant_name=unicode(restaurantInfo['name']),
                restaurant_address=unicode(restaurantInfo['address']),
                restaurant_image=restaurantInfo['image'])
            session.add(restaurant)
            session.commit()
            # return json object
            return jsonify(restaurant=restaurant.serialize)

    # return "show all restaurants"
    else:
        return jsonify({"error": "No restaurant found"})
Beispiel #8
0
def all_restaurants_handler():
    location = request.args.get('location', '')
    mealtype = request.args.get('mealtype', '')

    restaurantInfo = findARestaurant(mealtype, location)

    return jsonify(Restaurant=[restaurantInfo])
Beispiel #9
0
def all_restaurants_handler():
    if request.method == 'GET':
        showAllRestaurants()
    elif request.method == 'POST':
        location = request.args.get('location', '')
        mealType = request.args.get('mealType', '')
        restaurantInfo = findARestaurant(mealType, location)
        makeARestaurant(restaurantInfo)
Beispiel #10
0
def add_restaurant(location, mealType):
    resto_info = findARestaurant(mealType, location)
    print( resto_info )

    resto = Restaurant( restaurant_name=resto_info['name'], restaurant_address=resto_info['address'], restaurant_image=resto_info['image'] )

    session.add(resto)
    session.commit()
    return jsonify(resto = resto.serialize)
Beispiel #11
0
def makeARestaurant(location, mealType):
    session = DBSession()
    restaurant_info = findARestaurant(mealType, location)
    restaurant = Restaurant(restaurant_name=restaurant_info['name'],
                            restaurant_address=restaurant_info['address'],
                            restaurant_image=restaurant_info['image'])
    session.add(restaurant)
    session.commit()
    return jsonify(restaurant=restaurant.serialize)
Beispiel #12
0
def makeANewRestaurant(location, mealType):
    print(location)
    print(mealType)
    foursquare = findARestaurant(mealType, location)
    restaurant = Restaurant(restaurant_name=foursquare['name'],
                            restaurant_address=foursquare['address'],
                            restaurant_image=foursquare['image'])
    session.add(restaurant)
    session.commit()
    return jsonify(Restaurant=restaurant.serialize)
Beispiel #13
0
def dates():
    user_id = User.verify_auth_token(token)
    user_1 = session.query(User).filter_by(id=user_id).first().email

    if request.method == 'GET':
        dates = session.query(MealDate).all()
        return jsonify(dates=[d.serialize for d in dates])

    elif request.method == 'POST':
        user_2 = request.json.get('user_2')
        meal_time = request.json.get('meal_time')

        proposal = session.query(Proposal).filter_by(
            user_proposed_to=user_2).filter_by(
                user_proposed_from=user_1).first()
        requestMeal = session.query(RequestMeal).filter_by(
            id=proposal.request_id).first()

        meal_type = requestMeal.meal_type
        location_string = requestMeal.location_string

        restaurantInfo = findARestaurant(
            meal_type,
            location_string)  # name, address, picture of the restaurant.

        restaurant_name = restaurantInfo['name']
        restaurant_address = restaurantInfo['address']
        restaurant_picture = restaurantInfo['picture']

        if user_2 is None or meal_time is None:
            print "사용자와 식사 시간을 입력해주세요."
            abort(400)
        if restaurant_name is None or restaurant_address is None:
            print "레스토랑 정보를 입력해주세요"
            abort(400)

        dates = MealDate(user_1=user_1,
                         user_2=user_2,
                         restaurant_name=restaurant_name,
                         restaurant_address=restaurant_address,
                         restaurant_picture=restaurant_picture,
                         meal_time=meal_time)
        session.add(dates)
        session.commit()

        return jsonify({
            'user_1': dates.user_1,
            'user_2': dates.user_2,
            'restaurant_name': dates.restaurant_name,
            'restaurant_address': dates.restaurant_address,
            'restaurant_picture': dates.restaurant_picture,
            'meal_time': dates.meal_time
        })
Beispiel #14
0
def all_restaurants_handler():
    # Return all restaraunts in database.
    # If request method is GET, run a query on the database's Restaraunt table
    # (Class) for all restaraunts. Return value is a list of Restaurant objects.
    if request.method == 'GET':
        restaraunts = session.query(Restaurant).all()
        print(restaurants)

        # Query results (variable restaraunts which is a list data type) are
        # serialized, or, made into a dictionary then added to a list via a list
        # comprehension.  This list is then jsonfied for injestion by front end.
        return jsonify(restaurants=[i.serialize for i in restaraunts])

    # Make a new restaraunt and store it in the database.
    elif request.method == 'POST':
        # Flask.Request.args creates a MultiDict (dictionary subclass customized
        # to deal with multiple values for the same key which, is used by the
        # parsing functions in the wrappers. This is necessary because some HTML
        # form elements pass multiple values for the same key.) with the parsed
        # contents of the query string (strings in the URL after the "?").
        # Prototype: get(key, default=None, type=None)
        location = request.args.get('location', '')
        mealType = request.args.get('mealType', '')

        # Create restaraunt_info variable by calling the imported
        # findARestaurant function.
        restaurant_info = findARestaurant(mealType, location)

        # If there is restaraunt info, create a restaurant variable that is
        # equal to the instantiation of the Restaurant Class defined in our
        # model(models.py).
        if restaurant_info != "No Restaurants Found":
            restaurant = Restaurant(
                restaurant_name=unicode(restaurant_info['name']),
                restaurant_address=unicode(restaurant_info['address']),
                restaurant_image=restaurant_info['image'])
            # Add restaraunt variable just created to session.
            session.add(restaurant)
            # Commit Restaurant instance (restaurant variable created) to db.
            session.commit()

            # Return jsonified dictionary that results when object is serialized
            # via the Restaurant serialize attribute method.
            return jsonify(restaurant=restaurant.serialize)
        else:
            # If no restaurant data resulted from running findARestaurant on
            # the meal type and location passed in the address bar upon url
            # request, return error message.
            return jsonify({
                "error":
                f"No Restaurants Found for {mealType} in {location}"
            })
Beispiel #15
0
def enterFoodWants():
    if request.method == 'POST':
        location = request.form['location']
        foodType = request.form['foodType']
        restaurantInfo = findARestaurant(foodType, location, 5)
        session['restaurantInfo'] = restaurantInfo
        if restaurantInfo != "No Restaurants Found":
            newSearch = previousSearches(location=location, foodType=foodType)
            dbsession.add(newSearch)
            dbsession.commit()
            return render_template('result.html')
        else:
            return render_template('sorry.html')
Beispiel #16
0
def makeANewRestaurant(location, mealType):
    restaurantInfo = findARestaurant(mealType, location)
    if restaurantInfo == "No Restaurants Found":
        return "No Restaurants Found"

    newRestaurant = Restaurant(restaurant_name=restaurantInfo['name'],
                               restaurant_address=restaurantInfo['address'],
                               restaurant_image=restaurantInfo['image'])
    session.add(newRestaurant)
    session.commit()

    newRestaurant = session.query(Restaurant).filter_by(
        restaurant_name=restaurantInfo['name']).first()
    return jsonify(Restaurant=[newRestaurant.serialize])
Beispiel #17
0
def all_restaurants_handler():
    if request.method == 'POST':
        meal = request.args.get('mealType', '')
        location = request.args.get('location', '')
        restaurant = findARestaurant(meal, location)
        newRestaurant = Restaurant(restaurant_name=restaurant['name'],
                                   restaurant_address=restaurant['address'],
                                   restaurant_image=restaurant['image'])
        session.add(newRestaurant)
        session.commit()
        return jsonify(newRestaurant=newRestaurant.serialize)
    if request.method == 'GET':
        restaurants = session.query(Restaurant).all()
        return jsonify(restaurants=[r.serialize for r in restaurants])
Beispiel #18
0
def all_restaurants_handler():
	data = Data()
	if request.method == "POST":
		location = request.args.get('location')
		mealType = request.args.get('mealType')
		print(f'location = {location}, meal = {mealType}')
		if location == None or mealType == None:
			return 'Incorrect arguments'
		else:
			return findARestaurant(str(mealType).lower(), str(location).lower())
	elif request.method == "GET":
			restaurants = data.get_all_restaurants()
			return restaurants
	else:
		return 'Incorrect method used'
Beispiel #19
0
def all_restaurants_handler():
    #YOUR CODE HERE
    if request.method == 'GET':
        restaurants = session.query(Restaurant).all()
        return jsonify(Restaurants=[i.serialize for i in restaurants])
    elif request.method == 'POST':
        location = request.args.get('location', '')
        food = request.args.get('mealType', '')
        info = findARestaurant(food, location)
        restaurant = Restaurant(restaurant_name=info['name'],
                                restaurant_address=info['address'],
                                restaurant_image=info['pic'])
        session.add(restaurant)
        session.commit()
        return jsonify(Restaurant=restaurant.serialize)
Beispiel #20
0
def agree(proposal_id,id):
    proposal=session.query(Proposal).filter_by(id=proposal_id).first()
    user_1=session.query(User).filter_by(id=proposal.user_proposed_to).first()
    user_2=session.query(User).filter_by(id=proposal.user_proposed_from).first()
    request=session.query(Request).filter_by(id=proposal.request.id).first()
    restaurant_info=findARestaurant(request.meal_type,request.location_string)
    meatdata=MealDate()
    meatdata.user_1=user_1.id
    meatdata.user_2=user_2.id
    meatdata.restaurant_name=restaurant_info['name']
    meatdata.restaurant_address=restaurant_info['address']
    meatdata.meal_time=request.meal_time
    session.add(meatdata)
    session.commit()
    return render_template('agree.html',user=user_1)
Beispiel #21
0
def create_new_restaurant(mealType, location):
    if (mealType is not None) and \
       (location is not None):
        newResInfo = findARestaurant(mealType, location)
        newRes = Restaurant(restaurant_address = newResInfo.get('address'), \
                            restaurant_name = newResInfo.get('name'), \
                            restaurant_image = newResInfo.get('image'))
        session.add(newRes)
        session.commit()
        return jsonify(restaurant=newRes.serialize)

    else:
        error_msg = jsonify(error = \
            'Cannot create the restaurant. Some parameter(s) missing. ')
        return error_msg, 400
Beispiel #22
0
def create_newdate():
    errors = MealDate.validate(request.json)
    if len(errors) == 0:
        proposal_id = request.json.get('proposal_id')
        accept_proposal = request.json.get('accept_proposal')

        proposal = session.query(Proposal).filter_by(id=proposal_id).first()
        if proposal is None:
            return jsonify({'response': False})

        req = proposal.request
        if req.filled:
            return jsonify({'response': False})
        if accept_proposal:
            proposal.update({'filled': True})
            req.update({'filled': True})

            restaurant_name = ''
            restaurant_address = ''
            restaurant_picture = ''

            try:
                restaurant = findARestaurant(req.meal_type,
                                             req.location_string)
                if type(restaurant) == dict:
                    restaurant_name = restaurant['name']
                    restaurant_address = restaurant['address']
                    restaurant_picture = restaurant['image_url']
            except Exception as e:
                print e

            date = MealDate(
                user_1 = req.user_id,   \
                user_2 = proposal.user_proposed_from,   \
                restaurant_name =  restaurant_name,     \
                restaurant_address = restaurant_address,    \
                restaurant_picture = restaurant_picture,    \
                meal_time = req.meal_time   \
            )
            session.add(date)
            session.commit()
            return jsonify({'response': True}), 201
        else:
            session.delete(proposal)
            session.commit()
            return jsonify({'response': 'Deleted proposal'})
    else:
        return jsonify({'errors': errors}), 400
def all_restaurants_handler():
  if request.method == 'GET':
  	restaurants = session.query(Restaurant).all()
  	return jsonify(restaurants = [i.serialize for i in restaurants])

  elif request.method == 'POST':
    location = request.args.get('location', '')
    mealType = request.args.get('mealType', '')
    restaurant_info = findARestaurant(mealType, location)
    if restaurant_info != "No Restaurants Found":
      restaurant = Restaurant(restaurant_name = unicode(restaurant_info['name']), restaurant_address = unicode(restaurant_info['address']), restaurant_image = restaurant_info['image'])
      session.add(restaurant)
      session.commit() 
      return jsonify(restaurant = restaurant.serialize)
    else:
      return jsonify({"error":"No Restaurants Found for %s in %s" % (mealType, location)})
Beispiel #24
0
def all_restaurants_handler():
	session = manager.session
	if request.method == 'POST':
		cityName = request.args.get('cityName', 'Reno+Nevada')
		mealType = request.args.get('mealType', 'oysters')

		restaurant_data = findARestaurant(mealType, cityName)
		restaurant = Restaurant(restaurant_name=restaurant_data['name'], restaurant_address=restaurant_data['address'], restaurant_image=restaurant_data['image'])

		session.add(restaurant)
		session.commit()
		return jsonify(restaurant=restaurant.serialize)

	if request.method == 'GET':
		restaurants = session.query(Restaurant).all()
		return jsonify(restaurants=[r.serialize for r in restaurants])
Beispiel #25
0
def all_restaurants_handler():
  if request.method == 'GET':
  	restaurants = session.query(Restaurant).all()
  	return jsonify(restaurants = [i.serialize for i in restaurants])

  elif request.method == 'POST':
    location = request.args.get('location', '')
    mealType = request.args.get('mealType', '')
    restaurant_info = findARestaurant(mealType, location)
    if restaurant_info != "No Restaurants Found":
      restaurant = Restaurant(restaurant_name = unicode(restaurant_info['name']), restaurant_address = unicode(restaurant_info['address']), restaurant_image = restaurant_info['image'])
      session.add(restaurant)
      session.commit()
      return jsonify(restaurant = restaurant.serialize)
    else:
      return jsonify({"error":"No Restaurants Found for %s in %s" % (mealType, location)})
Beispiel #26
0
def all_restaurants_handler():
  if request.method == 'GET':
    res = session.query(Restaurant).all()
    return jsonify(restaurants = [r.serialize for r in res])

  elif request.method == 'POST':
    meal = request.args.get('mealType', '')
    loc = request.args.get('location', '')
    resInfo = findARestaurant(meal, loc)
    if resInfo != 'none':
      res = Restaurant(restaurant_name = unicode(resInfo['name']),
      restaurant_address = unicode(resInfo['address']),
      restaurant_image = resInfo['image'])
      session.add(res)
      session.commit()
      return jsonify(restaurant = res.serialize)
Beispiel #27
0
def restaurants():
    if request.method == 'GET':
        # restaurants = Restaurant.objects  # (id='59368a24756a44140214809e')
        return Restaurant.objects.to_json()
        # r = Restaurant._collection.find(Restaurant.objects()._query)
        # return json.dumps(restaurants, cls=MongoEncoder)
    elif request.method == 'POST':
        name, address, photo = findARestaurant(
            request.form.get('mealType'),
            request.form.get('location')
        )
        restaurant = Restaurant(
            name=name,
            address=address,
            photo=photo
        ).save()
        return restaurant.to_json()
Beispiel #28
0
def all_restaurants_handler():
    #YOUR CODE HERE
    if request.method == 'GET':
        restaurants = session.query(Restaurant).all()
        return jsonify(restaurants=[i.serialize for i in restaurants])
    if request.method == 'POST':
        location = request.args.get('location', '')
        mealType = request.args.get('mealType', '')
        print(location)
        print(mealType)
        restaurant_json = findARestaurant(mealType, location)
        restaurant = Restaurant(restaurant_name=restaurant_json['name'],
                                restaurant_address=restaurant_json['address'],
                                restaurant_image=restaurant_json['image'])
        session.add(restaurant)
        session.commit()
        return jsonify(restaurant=restaurant.serialize)
Beispiel #29
0
def createNewRestaurant(mealType, location):
    try:
        restaurant = findARestaurant(mealType, location)
        session = DBSession()
        if restaurant != 'Unable to find a restaurant.':
            newRestaurant = Restaurant(
                    name = unicode(restaurant['name']),
                    address = unicode(restaurant['address']),
                    image = unicode(restaurant['image'])
                )
            session.add(newRestaurant)
            session.commit()
            return jsonify(newRestaurant.serialize)
        else:
            return jsonify({"error":"No Restaurants Found for %s in %s" % (mealType, location)})
    except Exception as e:
        return jsonify({'error': 500, 'description': e})
Beispiel #30
0
def new_date():
    user = g.user
    if not request.json:
        abort(400)
    errors = MealDate.validate(request.json)
    if len(errors) == 0:
        proposalsa_id = request.json.get('proposal_id')
        accept_proposal = request.json.get('accept_proposal')
        proposal = session.query(Proposal).filter_by(id=proposal_id).first()
        if proposal is None:
            abort(404)
        r = proposal.request
        if r.filled:
            return jsonify({'result': False})
        if accept_proposal:
            proposal.filled = True
            r.filled = True
            restaurant_picture = "No Restaurants Found"
            restaurant_address = "No Restaurants Found"
            restaurant_name = "No Restaurants Found"
            try:
                result = findARestaurant(r.meal_type, r.location_string)
                if type(result) == dict:
                    restaurant_picture = result.get('name')
                    restaurant_address = result.get('address')
                    restaurant_name = result.get('image')
            except Exception as e:
                print e
            date = MealDate(meal_time=r.meal_time,
                            user_1=r.user_id,
                            user_2=proposal.user_proposed_from,
                            restaurant_picture=restaurant_picture,
                            restaurant_address=restaurant_address,
                            restaurant_name=restaurant_name)
            session.add(date)
            session.add(proposal)
            session.add(r)
            session.commit()
            return jsonify({'result': True})
        else:
            session.delete(proposal)
            session.commit()
            return jsonify({'result': True})

    return jsonify({"message": "The request is invalid."},
                   errors=[error for error in errors]), 400
Beispiel #31
0
def allRestaurant():
  if request.method == 'GET':
  	# RETURN ALL RESTAURANTS IN DATABASE
        return render_template('enterDetails.html')

  elif request.method == 'POST':
  	# MAKE A NEW RESTAURANT AND STORE IT IN DATABASE
    location = request.form['city']+", "+request.form['country']
    mealType = request.form['mealType']
    restaurant_info = findARestaurant(mealType, location)
    if restaurant_info != "No Restaurants Found":
      restaurant = RestaurantNear(restaurant_name = unicode(restaurant_info['name']), restaurant_address = unicode(restaurant_info['address']), restaurant_image = restaurant_info['image'])
      session.add(restaurant)
      session.commit() 
      return redirect(url_for('restaurantsNear'))
    else:
      return jsonify({"error":"No Restaurants Found for %s in %s" % (mealType, location)})
Beispiel #32
0
def createRestaurant(location, mealType):
    print 'inside createRestaurant'
    try:
        restaurant_info = findARestaurant(location, mealType)
        if restaurant_info != 'No Restaurants Found':
            print 'restaurant info: %s' % unicode(restaurant_info)
            newRestaurant = Restaurant(
                restaurant_name = unicode(restaurant_info['name']),
                restaurant_address = unicode(restaurant_info['address']),
                restaurant_image = restaurant_info['image']
            )
            session.add(newRestaurant)
            session.commit()
            return jsonify(restaurant = newRestaurant.serialize)
        else:
            return jsonify({'error':'No Restaurants returned for %s in %s' % (mealType, location)})
    except:
        return jsonify({'error':'Cannot retrive Restaurants for %s in %s' % (mealType, location)})
Beispiel #33
0
def all_restaurants_handler():
  if request.method == 'GET':
  	# RETURN ALL RESTAURANTS IN DATABASE
  	restaurants = session.query(Restaurant).all()
  	return jsonify(restaurants = [i.serialize for i in restaurants])

  elif request.method == 'POST':
  	# MAKE A NEW RESTAURANT AND STORE IT IN DATABASE

    location = request.json['location']
    mealType = request.json['mealType']    
    restaurant_info = findARestaurant(mealType, location)
    if restaurant_info != "No Restaurants Found":
      restaurant = Restaurant(restaurant_name = unicode(restaurant_info['name']), restaurant_address = unicode(restaurant_info['address']), restaurant_image = restaurant_info['image'])
      session.add(restaurant)
      session.commit() 
      return jsonify(restaurant = restaurant.serialize)
    else:
      return jsonify({"error":"No Restaurants Found for %s in %s" % (mealType, location)})
def new_date():
    user = g.user
    if not request.json:
        abort(400)
    errors = MealDate.validate(request.json)
    if len(errors) == 0:
        proposalsa_id = request.json.get('proposal_id')
        accept_proposal = request.json.get('accept_proposal')
        proposal = session.query(Proposal).filter_by(id = proposal_id).first()
        if proposal is None:
            abort(404)
        r = proposal.request
        if r.filled:
            return  jsonify( { 'result': False } )
        if accept_proposal:
            proposal.filled = True
            r.filled = True
            restaurant_picture = "No Restaurants Found"
            restaurant_address = "No Restaurants Found"
            restaurant_name =  "No Restaurants Found"
            try:
                result = findARestaurant(r.meal_type, r.location_string)
                if type(result) == dict:
                    restaurant_picture = result.get('name')
                    restaurant_address = result.get('address')
                    restaurant_name =  result.get('image')
            except Exception as e:
                 print e
            date = MealDate(meal_time = r.meal_time, user_1 = r.user_id , user_2 = proposal.user_proposed_from, restaurant_picture = restaurant_picture,restaurant_address = restaurant_address, restaurant_name= restaurant_name )
            session.add(date)
            session.add(proposal)
            session.add(r)
            session.commit()
            return  jsonify( { 'result': True } )
        else:
            session.delete(proposal)
            session.commit()
            return  jsonify( { 'result': True } )


    return jsonify({"message": "The request is invalid."},errors = [error for error in errors])  ,400