コード例 #1
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
コード例 #2
0
ファイル: restaurant.py プロジェクト: Eli10/user_service_api
    def get(self, name):
        restaurant = RestaurantModel.find_by_name(name)

        if restaurant:
            return restaurant.to_json()
        return {'message': 'Restaurant not registered'}, 404