Skip to content

Commit

Permalink
Merge pull request #39 from AndrewSergienko/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
andiserg authored Jul 27, 2023
2 parents 45cc102 + 714373f commit 92066fd
Show file tree
Hide file tree
Showing 88 changed files with 1,697 additions and 455 deletions.
11 changes: 11 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM python:3.10

ENV PYTHONUNBUFFERED 1

WORKDIR /app
COPY requirements.txt ./
RUN pip install -r requirements.txt --default-timeout=100

COPY . ./

EXPOSE 8000
29 changes: 29 additions & 0 deletions migration/versions/0c6eed52399f_.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
"""empty message
Revision ID: 0c6eed52399f
Revises: 804ce544203d
Create Date: 2023-06-11 10:12:39.465349
"""
import sqlalchemy as sa
from alembic import op

# revision identifiers, used by Alembic.
revision = "0c6eed52399f"
down_revision = "804ce544203d"
branch_labels = None
depends_on = None


def upgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.add_column("categories", sa.Column("parent_id", sa.Integer(), nullable=True))
op.create_foreign_key(None, "categories", "categories", ["parent_id"], ["id"])
# ### end Alembic commands ###


def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.drop_constraint(None, "categories", type_="foreignkey")
op.drop_column("categories", "parent_id")
# ### end Alembic commands ###
29 changes: 29 additions & 0 deletions migration/versions/48d00b4868c7_.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
"""empty message
Revision ID: 48d00b4868c7
Revises: 8db0b3c70d3d
Create Date: 2023-06-11 17:47:49.545536
"""
import sqlalchemy as sa
from alembic import op

# revision identifiers, used by Alembic.
revision = "48d00b4868c7"
down_revision = "8db0b3c70d3d"
branch_labels = None
depends_on = None


def upgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.add_column("limits", sa.Column("user_id", sa.Integer(), nullable=True))
op.create_foreign_key(None, "limits", "users", ["user_id"], ["id"])
# ### end Alembic commands ###


def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.drop_constraint(None, "limits", type_="foreignkey")
op.drop_column("limits", "user_id")
# ### end Alembic commands ###
45 changes: 45 additions & 0 deletions migration/versions/725589cc0adb_categories.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
"""categories
Revision ID: 725589cc0adb
Revises: 79110a6de7e7
Create Date: 2023-05-10 11:00:59.952790
"""
import sqlalchemy as sa
from alembic import op

# revision identifiers, used by Alembic.
revision = "725589cc0adb"
down_revision = "79110a6de7e7"
branch_labels = None
depends_on = None


def upgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.create_table(
"categories",
sa.Column("id", sa.Integer(), nullable=False),
sa.Column("name", sa.String(), nullable=False),
sa.Column("user_id", sa.Integer(), nullable=True),
sa.ForeignKeyConstraint(
["user_id"],
["users.id"],
),
sa.PrimaryKeyConstraint("id"),
)
op.add_column("operations", sa.Column("category_id", sa.Integer(), nullable=True))
op.create_foreign_key(None, "operations", "categories", ["category_id"], ["id"])
op.drop_column("operations", "mcc")
# ### end Alembic commands ###


def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.add_column(
"operations", sa.Column("mcc", sa.INTEGER(), autoincrement=False, nullable=True)
)
op.drop_constraint(None, "operations", type_="foreignkey")
op.drop_column("operations", "category_id")
op.drop_table("categories")
# ### end Alembic commands ###
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
"""change BankInfoProperty field names
Revision ID: 79110a6de7e7
Revises: 86f9d6304908
Create Date: 2023-05-02 23:57:37.004802
"""
import sqlalchemy as sa
from alembic import op

# revision identifiers, used by Alembic.
revision = "79110a6de7e7"
down_revision = "86f9d6304908"
branch_labels = None
depends_on = None


def upgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.add_column(
"banks_info_properties", sa.Column("prop_name", sa.String(), nullable=False)
)
op.add_column(
"banks_info_properties", sa.Column("prop_value", sa.String(), nullable=False)
)
op.add_column(
"banks_info_properties", sa.Column("prop_type", sa.String(), nullable=False)
)
op.drop_column("banks_info_properties", "name")
op.drop_column("banks_info_properties", "type")
op.drop_column("banks_info_properties", "value")
# ### end Alembic commands ###


def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.add_column(
"banks_info_properties",
sa.Column("value", sa.VARCHAR(), autoincrement=False, nullable=False),
)
op.add_column(
"banks_info_properties",
sa.Column("type", sa.VARCHAR(), autoincrement=False, nullable=False),
)
op.add_column(
"banks_info_properties",
sa.Column("name", sa.VARCHAR(), autoincrement=False, nullable=False),
)
op.drop_column("banks_info_properties", "prop_type")
op.drop_column("banks_info_properties", "prop_value")
op.drop_column("banks_info_properties", "prop_name")
# ### end Alembic commands ###
29 changes: 29 additions & 0 deletions migration/versions/804ce544203d_.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
"""empty message
Revision ID: 804ce544203d
Revises: f2d154c7bc55
Create Date: 2023-06-01 11:36:35.436792
"""
import sqlalchemy as sa
from alembic import op

# revision identifiers, used by Alembic.
revision = "804ce544203d"
down_revision = "f2d154c7bc55"
branch_labels = None
depends_on = None


def upgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.add_column("categories", sa.Column("icon_name", sa.String(), nullable=True))
op.add_column("categories", sa.Column("icon_color", sa.String(), nullable=True))
# ### end Alembic commands ###


def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.drop_column("categories", "icon_color")
op.drop_column("categories", "icon_name")
# ### end Alembic commands ###
38 changes: 38 additions & 0 deletions migration/versions/8db0b3c70d3d_.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
"""empty message
Revision ID: 8db0b3c70d3d
Revises: 0c6eed52399f
Create Date: 2023-06-11 17:45:07.399501
"""
import sqlalchemy as sa
from alembic import op

# revision identifiers, used by Alembic.
revision = "8db0b3c70d3d"
down_revision = "0c6eed52399f"
branch_labels = None
depends_on = None


def upgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.create_table(
"limits",
sa.Column("id", sa.Integer(), nullable=False),
sa.Column("category_id", sa.Integer(), nullable=True),
sa.Column("limit", sa.Integer(), nullable=True),
sa.Column("date_range", sa.String(), nullable=True),
sa.ForeignKeyConstraint(
["category_id"],
["categories.id"],
),
sa.PrimaryKeyConstraint("id"),
)
# ### end Alembic commands ###


def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table("limits")
# ### end Alembic commands ###
27 changes: 27 additions & 0 deletions migration/versions/f2d154c7bc55_.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
"""empty message
Revision ID: f2d154c7bc55
Revises: 725589cc0adb
Create Date: 2023-05-17 14:49:41.201539
"""
import sqlalchemy as sa
from alembic import op

# revision identifiers, used by Alembic.
revision = "f2d154c7bc55"
down_revision = "725589cc0adb"
branch_labels = None
depends_on = None


def upgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.add_column("categories", sa.Column("type", sa.String(), nullable=True))
# ### end Alembic commands ###


def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.drop_column("categories", "type")
# ### end Alembic commands ###
Binary file modified requirements.txt
Binary file not shown.
35 changes: 29 additions & 6 deletions src/app/adapters/orm.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
from sqlalchemy.orm import registry, relationship

from src.app.domain.bank_api import BankInfo, BankInfoProperty
from src.app.domain.categories import Category
from src.app.domain.limits import Limit
from src.app.domain.operations import Operation
from src.app.domain.users import User

Expand All @@ -26,13 +28,13 @@ def create_tables(mapper_registry) -> dict[str, Table]:
Column("amount", Integer, nullable=False),
Column("description", String),
Column("time", Integer, nullable=False),
Column("mcc", Integer),
# mcc - код виду операції
Column("source_type", String, nullable=False),
# Тип джерела.
# value: "manual" | "<bank_name>"
# Операція може бути або додана вручну або за допомогою API банку
Column("user_id", Integer, ForeignKey("users.id")),
Column("category_id", Integer, ForeignKey("categories.id"), nullable=True),
),
"banks_info": Table(
"banks_info",
Expand All @@ -45,11 +47,31 @@ def create_tables(mapper_registry) -> dict[str, Table]:
"banks_info_properties",
mapper_registry.metadata,
Column("id", Integer, primary_key=True),
Column("name", String, nullable=False),
Column("value", String, nullable=False),
Column("type", String, nullable=False),
Column("prop_name", String, nullable=False),
Column("prop_value", String, nullable=False),
Column("prop_type", String, nullable=False),
Column("manager_id", Integer, ForeignKey("banks_info.id")),
),
"categories": Table(
"categories",
mapper_registry.metadata,
Column("id", Integer, primary_key=True),
Column("name", String, nullable=False),
Column("user_id", Integer, ForeignKey("users.id"), nullable=True),
Column("type", String, default="system"),
Column("icon_name", String, nullable=True, default=None),
Column("icon_color", String, nullable=True, default=None),
Column("parent_id", Integer, ForeignKey("categories.id"), nullable=True),
),
"limits": Table(
"limits",
mapper_registry.metadata,
Column("id", Integer, primary_key=True),
Column("user_id", Integer, ForeignKey("users.id")),
Column("category_id", Integer, ForeignKey("categories.id"), nullable=True),
Column("limit", Integer),
Column("date_range", String),
),
}


Expand All @@ -68,10 +90,11 @@ def start_mappers(mapper_registry: registry, tables: dict[str, Table]):
mapper_registry.map_imperatively(
BankInfo,
tables["banks_info"],
properties={"properties": relationship(BankInfoProperty)},
properties={"properties": relationship(BankInfoProperty, backref="manager")},
)
mapper_registry.map_imperatively(
BankInfoProperty,
tables["banks_info_properties"],
properties={"manager": relationship(BankInfo)},
)
mapper_registry.map_imperatively(Category, tables["categories"])
mapper_registry.map_imperatively(Limit, tables["limits"])
14 changes: 7 additions & 7 deletions src/app/domain/bank_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,20 @@ class BankInfoProperty:

def __init__(
self,
name: str,
value: str,
value_type: str,
prop_name: str,
prop_value: str,
prop_type: str,
manager_id: int | None = None,
id: int = None,
manager: BankInfo | None = None,
):
self.name = name
self.value = value
self.type = value_type
self.prop_name = prop_name
self.prop_value = prop_value
self.prop_type = prop_type
self.manager_id = manager_id
self.id = id
self.manager = manager

def as_dict(self):
types = {"str": str, "int": int, "float": float}
return {f"{self.name}": types[self.type](self.value)}
return {f"{self.prop_name}": types[self.prop_type](self.prop_value)}
25 changes: 25 additions & 0 deletions src/app/domain/categories.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
class Category:
id: int | None
name: str
user_id: int | None
type: str
icon_name: str | None
icon_color: str | None

def __init__(
self,
name: str,
user_id: int | None,
type: str,
id: int | None = None,
icon_name: str | None = None,
icon_color: str | None = None,
parent_id: int | None = None,
):
self.id = id
self.name = name
self.user_id = user_id
self.type = type
self.icon_name = icon_name
self.icon_color = icon_color
self.parent_id = parent_id
Loading

0 comments on commit 92066fd

Please sign in to comment.