5 Commits

6 changed files with 82 additions and 1 deletions
+1
View File
@@ -1 +1,2 @@
__pycache__/ __pycache__/
*.env
+4
View File
@@ -13,3 +13,7 @@ docker-compose up
``` ```
That should be enough to get the server up and running. That should be enough to get the server up and running.
## Lab3 specifics
Variant for functionality extension: 27 % 3 = 0 => Income accountance
+47 -1
View File
@@ -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():
+7
View File
@@ -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'
+10
View File
@@ -12,3 +12,13 @@ services:
- "12402:12402" - "12402:12402"
volumes: volumes:
- ./app:/app/app - ./app:/app/app
env_file:
- db.env
depends_on:
- db
db:
restart: unless-stopped
image: postgres:17.2-alpine3.21
env_file:
- db.env
+13
View File
@@ -1,7 +1,20 @@
alembic==1.14.0
apispec==6.8.0
blinker==1.8.2 blinker==1.8.2
click==8.1.7 click==8.1.7
Flask==3.0.3 Flask==3.0.3
Flask-Migrate==4.0.7
flask-smorest==0.45.0
Flask-SQLAlchemy==3.1.1
greenlet==3.1.1
itsdangerous==2.2.0 itsdangerous==2.2.0
Jinja2==3.1.4 Jinja2==3.1.4
Mako==1.3.8
MarkupSafe==2.1.5 MarkupSafe==2.1.5
marshmallow==3.23.2
packaging==24.2
psycopg2-binary==2.9.10
SQLAlchemy==2.0.36
typing_extensions==4.12.2
webargs==8.6.0
Werkzeug==3.0.4 Werkzeug==3.0.4