Пример #1
0
    def post(self):
        data = self.parser.parse_args()
        new_restaurant = RestaurantModel(data['name'], data['address'].get('country', None), data['address'].get('city', None))

        new_restaurant.save_to_db()

        return new_restaurant.json(), 201
Пример #2
0
    def put(self, _id):
        data = self.parser.parse_args()
        restaurant = RestaurantModel.find_by_id(_id)

        if restaurant:
            restaurant.name = data['name']
        else:
            RestaurantModel(data['name'], data['address'].get('country', None), data['address'].get('city', None))

        restaurant.save_to_db()

        return restaurant.json(), (200 if restaurant else 201)
Пример #3
0
 def delete(self, _id):
   restaurant = RestaurantModel.find_by_id(_id)
   if restaurant:
     restaurant.destroy()
     return restaurant.json()
   else:
     return { "error": "not found" }, 404
Пример #4
0
 def get(self, rid):
     if RestaurantModel.find_by_id(rid) is None:
         return {
             'message': 'Restaurant <id:{}> not found.'.format(rid)
         }, 404
     menu_list = [menu.json() for menu in MenuModel.find_by_restaurant(rid)]
     return {'menus': menu_list}, 200
Пример #5
0
 def get(self):
     restaurants = RestaurantModel.get_all()
     if restaurants:
         return {
             'restaurants':
             [restaurant.to_json() for restaurant in restaurants]
         }, 200
     return {'message': 'User not registered'}, 404
Пример #6
0
    def delete(self, _id):
        restaurant = RestaurantModel.find_by_id(_id)

        if not restaurant:
            return {'message': f'No restaurant with id {_id}'}, 404

        restaurant.delete_from_db()

        return {'message': f'Item with {_id} deleted'}
Пример #7
0
    def get(self, name):
        restaurants = RestaurantModel.find_by_search_name(name)

        if restaurants:
            return {
                'restaurants':
                [restaurant.to_json() for restaurant in restaurants]
            }
        return {'message': 'Restaurant not registered'}, 404
Пример #8
0
 def patch(self, _id):
   restaurant = RestaurantModel.find_by_id(_id)
   data = Restaurant.parser.parse_args()
   if restaurant:
     restaurant.name = data['name']
     restaurant.address = data['address']
     restaurant.save()
     return restaurant.json()
   else:
     return { "error": "not found" }
Пример #9
0
    def put(self, id):  # update a restaurant
        user = current_identity
        #TODO: implement admin auth method
        # now assume only user.id = 1 indicates admin
        if user.id != 1:
            return {'message': UNAUTH_ERROR}, 401

        data = self.parser.parse_args()
        restaurant = RestaurantModel.find_by_id(id)
        if restaurant is None:
            return {'message': NOT_FOUND_ERROR.format(data['name'])}, 404
        # else update with given info restaurant
        if data['name']:
            restaurant.name = data['name']
        if data['fee']:
            restaurant.fee = data['fee']
        if data['limit']:
            restaurant.limit = data['limit']
        if data['address']:
            restaurant.address = data['address']
        if data['openTime']:
            restaurant.openTime = data['openTime']
        if data['closeTime']:
            restaurant.closeTime = data['closeTime']
        if data['isOpen'] is not None:
            restaurant.isOpen = data['isOpen']
        if data['logo']:
            restaurant.logo = data['logo']
        if data['promo']:
            restaurant.promo = data['promo']
        if data['phone']:
            restaurant.phone = data['phone']

        try:
            restaurant.save_to_db()
        except:
            traceback.print_exc()
            return {
                'message':
                INTERNAL_ERROR.format('Failed to update restaurant.')
            }, 500
        return restaurant.json(), 200
Пример #10
0
    def put(self, id):  # update a restaurant
        if not is_admin(current_identity):
            return {'message': 'Admin privilege not satisfied.'}, 401

        data = self.parser.parse_args()
        restaurant = RestaurantModel.find_by_id(id)
        if restaurant is None:
            return {'message': NOT_FOUND_ERROR.format(data['name'])}, 404
        # else update with given info restaurant
        if data['name']:
            restaurant.name = data['name']
        if data['fee']:
            restaurant.fee = data['fee']
        if data['limit']:
            restaurant.limit = data['limit']
        if data['address']:
            restaurant.address = data['address']
        if data['openTime']:
            restaurant.openTime = data['openTime']
        if data['closeTime']:
            restaurant.closeTime = data['closeTime']
        if data['isOpen'] is not None:
            restaurant.isOpen = data['isOpen']
        if data['logo']:
            restaurant.logo = data['logo']
        if data['promo']:
            restaurant.promo = data['promo']
        if data['phone']:
            restaurant.phone = data['phone']

        try:
            restaurant.save_to_db()
        except:
            traceback.print_exc()
            return {
                'message':
                INTERNAL_ERROR.format('Failed to update restaurant.')
            }, 500
        return restaurant.json(), 200
Пример #11
0
    def post(self):  # create a new restaurant
        data = self.parser.parse_args()
        if RestaurantModel.find_by_name(data['name']):
            return {'message': ALREADY_EXISTS_ERROR.format(data['name'])}, 400
        # else try to create new restaurant
        if data['isOpen'] is None:
            data['isOpen'] = True  # open by default

        # if data['logo'] is None:
        #     data['logo'] = default_logo_url

        res = RestaurantModel(None, **data)
        try:
            res.save_to_db()
        except:
            traceback.print_exc()
            return {
                'message':
                INTERNAL_ERROR.format('Failed to create restaurant.')
            }, 500
        return res.json(), 201
Пример #12
0
 def get(_id):
     restaurant = RestaurantModel.load_restaurant_by_id(_id)
     return restaurant
Пример #13
0
 def get(self, restaurantID):
     restaurant = RestaurantModel.find_by_id(restaurantID)
     if restaurant is None:
         return {'message': 'Restaurant <id:{}> not found.'.format(restaurantID)}, 404
     menu_list = [menu.json() for menu in restaurant.menu]
     return {'menus': menu_list}, 200
Пример #14
0
    def get(self, name):
        restaurant = RestaurantModel.find_by_name(name)

        if restaurant:
            return restaurant.to_json()
        return {'message': 'Restaurant not registered'}, 404
Пример #15
0
 def get(self):  # get all restaurants
     return {
         'restaurants': [res.json() for res in RestaurantModel.find_all()]
     }, 200
Пример #16
0
 def get(self, _id):
   restaurant = RestaurantModel.find_by_id(_id)
   if restaurant:
     return restaurant.json()
   else:
     return { "error": "Not found" }, 404
Пример #17
0
    def get(self, _id):
        restaurant = RestaurantModel.find_by_id(_id)

        return restaurant.json() if restaurant else ({'message': 'Restaurant not found'}, 404)
Пример #18
0
 def get():
     restaurants = RestaurantModel.load_restaurants()
     return restaurants
Пример #19
0
 def get():
     traditional_restaurants = RestaurantModel.load_traditional_restaurants(
     )
     return traditional_restaurants
Пример #20
0
 def post(self):
   data = Restaurants.parser.parse_args()
   restaurant = RestaurantModel(**data)
   restaurant.save()
   return restaurant.json(), 201