コード例 #1
0
 def get(self, name):
     store = StoreModel.find_store(name)
     if store:
         # return {'id':store.id,'name':store.name,'location':store.location,'inventory':[item.json() for item in store.items]}, 202
         return {
             'store': store.json(),
             'inventory': [item.json() for item in store.items]
         }, 202
コード例 #2
0
    def post(self, name):
        # add location to payload
        data = self.store_parser.parse_args()
        store_check = StoreModel.find_store(name)
        if store_check:
            return {'message': 'Store {} already exists.'.format(name)}, 400

        try:
            store = StoreModel(name=name, location=data['location'])
            store.insert_store()
        except:
            # in a real system I would need to log the Exception in addition to sending a response
            return {
                'message': 'Error, failed to add the store {}'.format(name)
            }, 500
        return {'message': 'Store {} has been added.'.format(store.name)}, 201
コード例 #3
0
 def delete(self, name):
     store = StoreModel.find_store(name)
     if store:
         try:
             store.delete_store()
         except:
             return {
                 'message':
                 'Error, failed to remove the store {}'.format(name)
             }, 500
         return {
             'message': 'Store {} has been removed'.format(store.name)
         }, 200
     return {
         'message': 'Store {} does not exist to remove.'.format(name)
     }, 400
コード例 #4
0
    def put(self, name):
        data = self.store_parser.parse_args()
        store = StoreModel.find_store(name)
        if store:
            store.location = data['location']
            event = "updated"
        else:
            store = StoreModel(name=name, location=data['location'])
            event = "inserted"

        try:
            store.save_store()
        except:
            return {
                'message':
                'Error, store {} failed to be {}.'.format(name, event)
            }, 500
        return {
            'message':
            'Store {} {} to location {}.'.fromat(store.name, event,
                                                 store.location)
        }, 201
コード例 #5
0
 def get(self, name):
     store = StoreModel.find_store(name)
     if store:
         return {'store': store.json()}, 200
     return {'message': 'Store {} not found.'.format(name)}, 404