Пример #1
0
 def delete(self, name):
     account = AccountModel.find_by_name(name)
     if account:
         mall = MallModel.find_by_id(account.id)
         if mall:
             mall.delete_from_db()
         account.delete_from_db()
         return {'message': "Account with name '{}' deleted".format(name)}
     return {'message': 'Account not found.'}, 404
Пример #2
0
    def put(self, name):
        data = Account.parser.parse_args()

        account = AccountModel.find_by_name(name)

        if account is None:
            account = AccountModel(name, **data)
        else:
            account.is_active = data['is_active']

        account.save_to_db()
        return account.json()
Пример #3
0
    def post(self, name):
        if AccountModel.find_by_name(name):
            return {
              "message": "An item with name '{}' already exists."
              .format(name)}, 400

        data = Account.parser.parse_args()

        account = AccountModel(name, **data)

        try:
            account.save_to_db()
        except:
            return {"message": "An error occurred adding the account."}, 500

        return account.json(), 201
Пример #4
0
 def delete(self, name):
     account = AccountModel.find_by_name(name)
     if account is None:
         return {'message': "No account exists."}
     account.delete_from_db()
     return {'message': "Account deleted"}
Пример #5
0
 def get(self, name):
     account = AccountModel.find_by_name(name)
     if account:
         return account.json()
     else:
         return {'message': 'Account not found'}, 404