コード例 #1
0
 def post(self, name):
     store = StoreModel.find_by_name(name)
     if store is None:
         store = StoreModel(name)
         store.save_to_db()
         return store.json()
     return {"message": "Store {} is already existed".format(name)}
コード例 #2
0
ファイル: store.py プロジェクト: gulshngill/store_rest_api_gg
 def get(self, name):
     store = StoreModel.find_by_name(name)
     if store:
         return store.json()
     return {
         'message': 'store not found'
     }, 404  #returned as a tuple and flask know which to assign to body and status code
コード例 #3
0
    def delete(self, name):
        store = StoreModel.find_by_name(name)

        if store:
            store.delete_from_db()

        return {"message": "Store deleted"}
コード例 #4
0
ファイル: store.py プロジェクト: gulshngill/store_rest_api_gg
    def delete(self, name):
        store = StoreModel.find_by_name(name)
        if store:
            store.delete_from_db()
            return {'message': 'Store {} has been deleted'.format(name)}

        return {'message': 'store does not exist!'}
コード例 #5
0
ファイル: stores.py プロジェクト: VladZg/Flask_project
 def delete(name):
     abort_if_store_doesnt_exist(name)
     deleted_store = StoreModel.find_by_name(name)
     if not ItemModel.query.filter_by(store_id=deleted_store.id).all():
         deleted_store.delete_store()
         return {'message': "store '{}' was deleted".format(name)}, 201
     else:
         return {'message': "store '{}' have to be empty".format(name)}, 201
コード例 #6
0
ファイル: store.py プロジェクト: VasuDholakiya2810/FLask_Api
 def post(self, name):
     if StoreModel.find_by_name(name):
         return {
             "message": "Store {name} is already exists".format(name=name)
         }, 400
     store = StoreModel(name)
     store.save_to_db()
     return store.json()
コード例 #7
0
 def post(self, name):
     if StoreModel.find_by_name(name):
         return {"massage": "store {} already exits.".format(name)}, 400
     store = StoreModel(name)
     try:
         store.save()
         return store.json()
     except:
         return {"massage": "inserting store {} was not successful".format(name)}, 500
コード例 #8
0
 def delete(self, name):
     store = StoreModel.find_by_name(name)
     if store:
         try:
             store.delete()
             return {"massage": "deleting item {} was successful".format(name)}, 200
         except:
             return {"massage": "deleting item {} was not successful".format(name)}, 500
     else:
         return {"massage": "item {} doesn't exist in database"}
コード例 #9
0
ファイル: store.py プロジェクト: Ashish-Dhamu/FlaskAPI
 def post(self, name):
     if StoreModel.find_by_name(name):
         return {"message":"Store {} is already there.".format(name)}, 400
     
     store  = StoreModel(name)
     try:
         store.save_to_db()
     except:
         return {"message":"An internal error occured while creating store."}, 500
     return store.json(), 201
コード例 #10
0
    def post (self,name):
        if StoreModel.find_by_name(name):
            return {'message' : "A store with that name'{}'alredy exists.".format(name)},400

        store = StoreModel(name)
        try : 
            store.save_to_db()
        except :
            return {'message' : 'An error occured while creating the store.'},500

        return store.json(), 201
コード例 #11
0
ファイル: store.py プロジェクト: gulshngill/store_rest_api_gg
    def post(self, name):
        if StoreModel.find_by_name(name):  #if store already exists
            return {'message': 'Store {} already exists'.format(name)}, 400

        store = StoreModel(name)  #create store model

        try:
            store.save_to_db()
        except:
            return {'message': 'An error has occured'}, 500

        return store.json(), 201
コード例 #12
0
ファイル: stores.py プロジェクト: VladZg/Flask_project
 def put(name):
     if does_store_exist(name):
         changed_store = StoreModel.find_by_name(name)
         new_name = Store.parser.parse_args()['new_name']
         abort_if_store_exist(new_name)
         changed_store.name = new_name
         db.session.commit()
         return {'changed_store': changed_store.json()}, 201
     new_store = {'name': name}
     new_store = StoreModel(**new_store)
     new_store.add_store()
     return {'new_store': new_store.json()}, 201
コード例 #13
0
    def post(self, name):
        if StoreModel.find_by_name(name):
            return {'message': f'A store with name {name} already exists'}, 400

        store = StoreModel(name)
        try:
            store.save_to_db()
        except:
            return {
                'message': 'An error occured while creating the store'
            }, 500
        return store.json(), 201
コード例 #14
0
 def post(self, name):
     if StoreModel.find_by_name(name):
         return {
             'message':
             'The item with the given name: {} already exists'.format(name)
         }, 400
     store = StoreModel(name)
     try:
         store.save_to_db()
     except:
         return {
             "message": "AN error occured during Insertion"
         }, 500  # Internal Sever error
     return store.json(), 201  #status Code
コード例 #15
0
    def post(self, name):

        if StoreModel.find_by_name(name):
            return {
                "message": "A store with name {} already exists .".format(name)
            }, 400

        store = StoreModel(name)
        try:
            store.save_to_db()
        except:
            return {"message": "An error occurred while creating store"}, 500

        return store.json()
コード例 #16
0
ファイル: store.py プロジェクト: shaibow/python-flask-course
    def post(self, name):
        store = StoreModel.find_by_name(name)

        try:
            if store:
                return {
                    'message': 'store with name {} exists'.format(name)
                }, 400
        except:
            return {'message': 'error in saving store'}, 500

        store = StoreModel(name)
        store.save_to_database()
        return store.json()
コード例 #17
0
    def post(self, name):
        if StoreModel.find_by_name(name):
            return {
                'message': 'A Store with name {} is already there'.format(name)
            }, 400

        store = StoreModel(name)
        try:
            store.save_to_db()
        except:
            return {
                'message':
                'An error occured while inserting item into database'
            }, 500

        return store.json(), 201
コード例 #18
0
ファイル: store.py プロジェクト: uwevanopfern/Flask-REST-API-
    def post(self, name):
        if StoreModel.find_by_name(name):
            return {
                'message':
                "Store with this name '{}' already exists.".format(name)
            }, 400

        store = StoreModel(name)

        try:
            store.save_to_db()  # Save into database

        except 'Exception':

            return {"message": "Error occurred while inserting store"}, 500

        return store.json(), 201
コード例 #19
0
ファイル: store.py プロジェクト: Ashish-Dhamu/FlaskAPI
    def get(self, name):
        store = StoreModel.find_by_name(name)

        if store:
            return store.json()
        return {"message":"Store not found"}, 404
コード例 #20
0
 def get(self, name):
     store = StoreModel.find_by_name(name)
     if store:
         return store.json()
     return {"message": "Store does not exists."}, 404
コード例 #21
0
 def delete(self, name):
     store = StoreModel.find_by_name(name)
     if store:
         store.delete_from_db()
     return {"message": "The store is deleted Successfully"}
コード例 #22
0
ファイル: stores.py プロジェクト: VladZg/Flask_project
def does_store_exist(name):
    if StoreModel.find_by_name(name) is not None:
        return True
    return False
コード例 #23
0
ファイル: store.py プロジェクト: shaibow/python-flask-course
 def delete(self, name):
     store = StoreModel.find_by_name(name)
     if store:
         store.delete_from_database()
         return {'message': 'sotre deleted'}
     return {'message': 'store dont exist'}, 404
コード例 #24
0
 def delete(self, name):
     store = StoreModel.find_by_name(name)
     if store is None:
         return {"message": "{} not found".format(name)}
     store.delete()
     return {"message": "{} is deleted".format(name)}
コード例 #25
0
ファイル: store.py プロジェクト: shaibow/python-flask-course
 def get(self, name):
     store = StoreModel.find_by_name(name)
     if store:
         return store.json()
     return {'message': 'Store didnt exits'}, 404
コード例 #26
0
ファイル: stores.py プロジェクト: VladZg/Flask_project
 def get(name):
     abort_if_store_doesnt_exist(name)
     store = StoreModel.find_by_name(name)
     return {'store': store.json()}, 201
コード例 #27
0
ファイル: store.py プロジェクト: VasuDholakiya2810/FLask_Api
 def get(self, name):
     store = StoreModel.find_by_name(name)
     if store:
         return store.json()
     return {"message": "Store Not Found...".format(name)}, 404
コード例 #28
0
ファイル: store.py プロジェクト: VasuDholakiya2810/FLask_Api
 def delete(self, name):
     store = StoreModel.find_by_name(name)
     if store:
         store.delete()
         return {"message": "item deleted..."}
     return {"message": "No {} store".format(name)}
コード例 #29
0
 def delete(self, name):
     store = StoreModel.find_by_name(name)
     if store:
         store.delete_from_db()
     return {'message': 'Store has been deleted'}
コード例 #30
0
 def get(self, name):
     store = StoreModel.find_by_name(name)
     if store:
         return store.json()
     return {'message': 'Store not found'}, 404