Skip to content

Commit

Permalink
Merge branch 'develop' into feature/add_webhook
Browse files Browse the repository at this point in the history
  • Loading branch information
ArtemBalandin81 authored Aug 15, 2023
2 parents 391c215 + e8820b8 commit 4e5b36a
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 1 deletion.
19 changes: 18 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ structlog = "^23.1.0"
asgi-correlation-id = "^4.2.0"
rich = "^13.3.5"
fastapi-mail = "^1.4.0"
werkzeug = "^2.3.6"


[tool.poetry.group.dev.dependencies]
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,4 @@ starlette==0.27.0 ; python_version >= "3.11" and python_version < "4.0"
structlog==23.1.0 ; python_version >= "3.11" and python_version < "4.0"
typing-extensions==4.7.1 ; python_version >= "3.11" and python_version < "4.0"
uvicorn==0.21.1 ; python_version >= "3.11" and python_version < "4.0"
werkzeug==2.3.6 ; python_version >= "3.11" and python_version < "4.0"
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
"""add_admin_user_model
Revision ID: 9ce2090b58a9
Revises: 42469a350651
Create Date: 2023-08-13 15:31:22.429548
"""
import sqlalchemy as sa
from alembic import op

# revision identifiers, used by Alembic.
revision = "9ce2090b58a9"
down_revision = "42469a350651"
branch_labels = None
depends_on = None


def upgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.create_table(
"admin_token_requests",
sa.Column("email", sa.String(length=48), nullable=False),
sa.Column("token", sa.String(length=128), nullable=False),
sa.Column("token_expiration_date", sa.Date(), nullable=False),
sa.Column("id", sa.Integer(), nullable=False),
sa.Column("created_at", sa.Date(), server_default=sa.text("CURRENT_TIMESTAMP"), nullable=False),
sa.Column("updated_at", sa.Date(), server_default=sa.text("CURRENT_TIMESTAMP"), nullable=False),
sa.PrimaryKeyConstraint("id"),
sa.UniqueConstraint("email"),
)
op.create_table(
"admin_users",
sa.Column("email", sa.String(length=48), nullable=False),
sa.Column("first_name", sa.String(length=64), nullable=True),
sa.Column("last_name", sa.String(length=64), nullable=True),
sa.Column("password", sa.String(length=128), nullable=False),
sa.Column("last_logon", sa.Date(), nullable=False),
sa.Column("id", sa.Integer(), nullable=False),
sa.Column("created_at", sa.Date(), server_default=sa.text("CURRENT_TIMESTAMP"), nullable=False),
sa.Column("updated_at", sa.Date(), server_default=sa.text("CURRENT_TIMESTAMP"), nullable=False),
sa.PrimaryKeyConstraint("id"),
sa.UniqueConstraint("email"),
)
op.alter_column("external_site_users", "specializations", existing_type=sa.VARCHAR(), nullable=True)
# ### end Alembic commands ###


def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.alter_column("external_site_users", "specializations", existing_type=sa.VARCHAR(), nullable=False)
op.drop_table("admin_users")
op.drop_table("admin_token_requests")
# ### end Alembic commands ###
31 changes: 31 additions & 0 deletions src/core/db/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from sqlalchemy.ext.declarative import AbstractConcreteBase
from sqlalchemy.orm import DeclarativeBase, Mapped, backref, mapped_column, relationship
from sqlalchemy.sql import expression, func
from werkzeug.security import check_password_hash, generate_password_hash


class Base(DeclarativeBase):
Expand Down Expand Up @@ -110,3 +111,33 @@ class Category(ContentBase):

def __repr__(self):
return f"<Category {self.name}>"


class AdminUser(Base):
__tablename__ = "admin_users"

email: Mapped[str] = mapped_column(String(48), unique=True)
first_name: Mapped[str] = mapped_column(String(64), nullable=True)
last_name: Mapped[str] = mapped_column(String(64), nullable=True)
password: Mapped[str] = mapped_column(String(128))
last_login: Mapped[date]

def __repr__(self):
return f"<Admin User {self.first_name} {self.last_name}>"

def set_password(self, password):
self.password = generate_password_hash(password)

def check_password(self, password):
return check_password_hash(self.password, password)


class AdminTokenRequest(Base):
__tablename__ = "admin_token_requests"

email: Mapped[str] = mapped_column(String(48), unique=True)
token: Mapped[str] = mapped_column(String(128))
token_expiration_date: Mapped[date]

def __repr__(self):
return f"<Register {self.email}>"
13 changes: 13 additions & 0 deletions src/core/db/repository/admin_repository.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from fastapi import Depends
from sqlalchemy.ext.asyncio import AsyncSession

from src.core.db.db import get_session
from src.core.db.models import AdminUser
from src.core.db.repository.base import AbstractRepository


class AdminUserRepository(AbstractRepository):
"""Репозиторий для работы с моделью AdminUser."""

def __init__(self, session: AsyncSession = Depends(get_session)) -> None:
super().__init__(session, AdminUser)

0 comments on commit 4e5b36a

Please sign in to comment.