add database and marshmallow entities to app
This commit is contained in:
parent
a5c5c1850d
commit
9fe9a112e7
|
@ -3,8 +3,54 @@ import time
|
||||||
import json
|
import json
|
||||||
from app.local_db import LocalDB
|
from app.local_db import LocalDB
|
||||||
|
|
||||||
|
from marshmallow import Schema, fields
|
||||||
|
from flask_sqlalchemy import SQLAlchemy
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
ldb = LocalDB()
|
app.config.from_pyfile('config.py', silent=True)
|
||||||
|
|
||||||
|
db = SQLAlchemy(app)
|
||||||
|
|
||||||
|
class UserModel(db.Model):
|
||||||
|
__tablename__ = "user"
|
||||||
|
uuid = db.Column(db.String(32), unique=True, primary_key=True, nullable=False)
|
||||||
|
name = db.Column(db.String(64), nullable=False)
|
||||||
|
|
||||||
|
records = db.relationship('RecordSchema', backref='user.uuid')
|
||||||
|
|
||||||
|
class CategoryModel(db.Model):
|
||||||
|
__tablename__ = "category"
|
||||||
|
uuid = db.Column(db.String(32), unique=True, primary_key=True, nullable=False)
|
||||||
|
name = db.Column(db.String(64), nullable=False)
|
||||||
|
|
||||||
|
records = db.relationship('RecordSchema', backref='category.uuid')
|
||||||
|
|
||||||
|
class RecordSchema(db.Model):
|
||||||
|
__tablename__ = "record"
|
||||||
|
uuid = db.Column(db.String(32), primary_key=True, nullable=False)
|
||||||
|
user_uuid = db.Column(db.String(32), db.ForeignKey('user.uuid'))
|
||||||
|
cat_uuid = db.Column(db.String(32), db.ForeignKey('category.uuid'))
|
||||||
|
date = db.Column(db.Date)
|
||||||
|
amount = db.Column(db.Integer)
|
||||||
|
|
||||||
|
class UserSchema(Schema):
|
||||||
|
uuid = fields.Str()
|
||||||
|
name = fields.Str()
|
||||||
|
|
||||||
|
class CategorySchema(Schema):
|
||||||
|
uuid = fields.Str()
|
||||||
|
name = fields.Str()
|
||||||
|
|
||||||
|
class RecordSchema(Schema):
|
||||||
|
uuid = fields.Str()
|
||||||
|
user_uuid = fields.Str()
|
||||||
|
cat_uuid = fields.Str()
|
||||||
|
date = fields.Date()
|
||||||
|
amount = fields.Integer()
|
||||||
|
|
||||||
|
# "migration"
|
||||||
|
with app.app_context():
|
||||||
|
db.create_all()
|
||||||
|
|
||||||
@app.route("/healthcheck")
|
@app.route("/healthcheck")
|
||||||
def ep_healthcheck():
|
def ep_healthcheck():
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
import os
|
||||||
|
|
||||||
|
PROPAGATE_EXCEPTIONS = True
|
||||||
|
SQLALCHEMY_DATABASE_URI = f'postgresql://{os.environ["POSTGRES_USER"]}:{os.environ["POSTGRES_PASSWORD"]}@db:5432/accountance'
|
||||||
|
SQLALCHEMY_TRACK_MODIFICATIONS = False
|
||||||
|
API_TITLE = "Finance REST API"
|
||||||
|
API_VERSION = 'v1'
|
Loading…
Reference in New Issue