Exemple #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
    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
Exemple #3
0
 def post(self):
   data = Restaurants.parser.parse_args()
   restaurant = RestaurantModel(**data)
   restaurant.save()
   return restaurant.json(), 201