Esempio n. 1
0
 def post(cls):
     restaurant_name = request.json['name']
     location = request.json['location']
     phone = request.json['phone']
     email = request.json['email']
     no_of_seats = request.json['max_seats']
     restaurant = Restaurant(email=email,
                             phone=phone,
                             location=location,
                             restaurant_name=restaurant_name,
                             no_of_seats=no_of_seats)
     restaurant.save_to_db()
     return restaurant.to_json(), 201
Esempio n. 2
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()