-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
56 lines (45 loc) · 1.47 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
from datetime import datetime
from flask import Flask, request, jsonify
from flask_sqlalchemy import SQLAlchemy
app = Flask(__name__)
app.config['JSON_SORT_KEYS'] = False
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///db.sqlite3'
db = SQLAlchemy(app)
class Transaction(db.Model):
id = db.Column(db.Integer, primary_key=True)
establishment = db.Column(db.String, nullable=False)
custumer = db.Column(db.String, nullable=False)
value = db.Column(db.Float, nullable=False)
description = db.Column(db.String(100), nullable=False)
date_created = db.Column(db.DateTime, default=datetime.utcnow)
@app.route('/transaction', methods=['POST'])
def transaction():
json = request.json
verify_body = True
if not json:
verify_body = False
for key in json:
response = json[key]
if not response:
verify_body = False
if verify_body:
transaction = Transaction(
establishment=json["estabelecimento"],
custumer=json["cliente"],
value=json["valor"],
description=json["descricao"]
)
db.session.add(transaction)
db.session.commit()
msg = {
"aceito": True
}
return jsonify(msg), 201
else:
msg = {
"error": "body or field empty"
}
return jsonify(msg), 400
if __name__ == "__main__":
app.run(debug=True, host='0.0.0.0')