Beispiel #1
0
    def put(self):
        data = Transaction.parser.parse_args()

        transaction = TransactionModel.find_by_id(data['id'])

        if transaction is None:
            transaction = TransactionModel(
                datetime.strptime(data['date'],
                                  "%Y-%m-%d"), data['vendor'].lower(),
                data['category'].lower(), data['price'])
        else:
            transaction.date = datetime.strptime(data['date'], "%Y-%m-%d")
            transaction.vendor = data['vendor'].lower()
            transaction.category = data['category'].lower()
            transaction.price = data['price']

        try:
            transaction.save_to_db()
        except:
            return {
                "message":
                "An error occurred inserting/updating the transaction."
            }, 500

        return transaction.json()
Beispiel #2
0
    def delete(self):
        data = Transaction.parser.parse_args()

        transaction = TransactionModel.find_by_id(data['id'])
        if transaction:
            transaction.delete_from_db()

        return {"message": "Transaction deleted."}
Beispiel #3
0
    def get(self):
        data = Transaction.parser.parse_args()
        transaction = TransactionModel.find_by_id(data['id'])

        if transaction:
            return transaction.json()
        else:
            return {"message": "Transaction not found."}, 404
Beispiel #4
0
    def get(self, user_id, _id):
        if user_id == get_jwt_identity():
            transaction = TransactionModel.find_by_id(user_id, _id)

            if transaction and transaction.user_id == get_jwt_identity():
                return transaction_schema.dump(transaction), 200

            return {'message': 'Transaction not found'}

        return {'message': 'You can only fetch your own transactions'}
Beispiel #5
0
    def delete(self, user_id, _id):
        if user_id == get_jwt_identity():
            transaction = TransactionModel.find_by_id(user_id, _id)

            if transaction and transaction.user_id == get_jwt_identity():
                transaction.delete_from_db()
                return {'message': f'Transaction with id:{_id} deleted'}, 200

            return {'message': 'Transaction not found'}, 404

        return {'message': 'You can only delete your own transactions'}, 401
Beispiel #6
0
    def put(self, user_id, _id):
        if user_id == get_jwt_identity():
            transaction_json = request.get_json()
            transaction = TransactionModel.find_by_id(user_id, _id)

            if transaction:
                for key in transaction_json:
                    setattr(transaction, key, transaction_json[key])
                transaction.save_to_db()
                return transaction_schema.dump(transaction), 200

            return {'message': 'Transaction not found'}, 404

        return {'message': 'You can only edit your own transactions'}, 401
Beispiel #7
0
    def delete(self, name):
        transaction = TransactionModel.find_by_id(name)
        if transaction:
            transaction.delete_from_db()

        return {'message': 'Transaction deleted'}
Beispiel #8
0
 def get(self, trans_id):
     transaction = TransactionModel.find_by_id(trans_id)
     if transaction:
         return transaction.json()
     return {'message': 'Transaction not found'}, 404
Beispiel #9
0
 def generate():
     while True:
         yield "<p>{}</p>".format(TransactionModel.find_by_id(transId))
         sleep(300)