Ejemplo n.º 1
0
    def put(self, name):
        data = Store.parser.parse_args()
        store = StoreModel.find_by_name(name)

        if store is None:
            new_item = StoreModel(None, name, data['price'], data['store_id'])
            try:
                new_item.save_to_db()
                new_item = StoreModel.find_by_name(name)
            except:
                return {
                    'message': 'An error occurred inserting the store'
                }, 500  # Internal Server Error
            return new_item.json(), 201

        else:
            store.price = data['price']
            store.store_id = data['store_id']
            try:
                store.save_to_db()
                store = StoreModel.find_by_name(name)
            except:
                return {
                    'message': 'An error occurred updating the store'
                }, 500  # Internal Server Error
        return {'message': "Updated successfully", 'store': store.json()}
Ejemplo n.º 2
0
 def post(self, name):
     if StoreModel.find_by_name(name):
         return {
             'Message': "The store '{}' is already exist".format(name)
         }, 400
     new_store = StoreModel(None, name)
     try:
         new_store.save_to_db()
         new_store = StoreModel.find_by_name(name)
     except:
         return {
             'message': 'An error occurred inserting the item'
         }, 500  # Internal Server Error
     return new_store.json(), 201
Ejemplo n.º 3
0
    def delete(self, name):
        store = StoreModel.find_by_name(name)

        if store:
            store.delete_from_db()

        return {'message': 'Store deleted'}
Ejemplo n.º 4
0
    def post(self, name):
        if StoreModel.find_by_name(name):
            return {"message": "Store already exists."}, 400
        store = StoreModel(name)
        try:
            store.save_to_db()
        except:
            return {"message": "An arror occurd during creating store"}, 500

        return store.json, 201
Ejemplo n.º 5
0
    def post(self, name):
        if StoreModel.find_by_name(name):
            return {"message": "Store {} already exists".format(name)}, 400
        store = StoreModel(name)

        try:
            store.save_to_db()
        except:
            return {"message": "Error occured creating db"}, 500

        return store.json(), 201
Ejemplo n.º 6
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 the store"}, 500

        return store.json()
Ejemplo n.º 7
0
    def post(self, name):
        if StoreModel.find_by_name(name):
            return {'message': f"A store with name {name} already exist"}, 400

        store = StoreModel(name)
        try:
            store.save_to_db()
        except:
            return {'message': 'Error while parsing via server'}, 500

        return store.json(), 201
Ejemplo n.º 8
0
 def delete(self, name):
     store = StoreModel.find_by_name(name)
     if store is None:
         return {'Message': "The store '{}' is not exist".format(name)}, 404
     try:
         store.delete_from_db()
     except:
         return {
             'message': 'An error occurred deleting the store'
         }, 500  # Internal Server Error
     return {'message': "The store '{}' has been deleted".format(name)}
Ejemplo n.º 9
0
    def post(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 ConnectionError:
            return {"message": "An error occurred creating the store."}, 500

        return store.json(), 201
Ejemplo n.º 10
0
    def post(self, name):

        if StoreModel.find_by_name(name):
            return {
                'message': "A store with name '{}' already exists".format(name)
            }, 400  # 400 => BAD REQUEST

        # Store.parser.parse_args()

        store = StoreModel(name)

        try:
            store.save_to_db()
        except:
            return {'message': 'An error ocurred inserting item.'}, 500

        return store.json(), 201  # 201 => CREATED
Ejemplo n.º 11
0
    def get(self, name):
        store = StoreModel.find_by_name(name)
        if store:
            return store.json()

        return {"message": "Store not found"}, 404
Ejemplo n.º 12
0
    def get(self, name):
        store = StoreModel.find_by_name(name)
        if store:
            return store.json()

        return {'message': 'Store not found'}, 404
Ejemplo n.º 13
0
 def delete(self, name):
     store = StoreModel.find_by_name(name)
     if store:
         store.delete_from_db()
     return {"message": "Store deleted."}, 200