Exemple #1
0
 def post(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 occurred while creating the store'
         }, 500
     return store.json(), 201
 def get(self, name):
     store = StoreModel.find_by_name(name)
     if store:
         return store.json()
     return {'message': 'Store not found'}, 404
    def delete(self, name):
        store = StoreModel.find_by_name(name)
        if store:
            store.delete_from_db()

        return {'message': 'Store deleted'}
Exemple #4
0
 def get():
     return {'stores': [store.json() for store in StoreModel.find_all()]}