From bfb0d9f78ff6491a9bf26be1e3025ff98422b8ff Mon Sep 17 00:00:00 2001 From: Nox Date: Mon, 16 Oct 2023 01:08:25 -0300 Subject: [PATCH] added created_at to user model --- identity_socializer/db/dao/user_dao.py | 4 ++-- .../versions/2023-09-21-17-33_847eee4ea866.py | 1 + identity_socializer/db/models/user_model.py | 8 ++++++++ identity_socializer/web/api/auth/schema.py | 7 ------- identity_socializer/web/api/auth/views.py | 11 ++++------- 5 files changed, 15 insertions(+), 16 deletions(-) diff --git a/identity_socializer/db/dao/user_dao.py b/identity_socializer/db/dao/user_dao.py index 9880dda..f991cfb 100644 --- a/identity_socializer/db/dao/user_dao.py +++ b/identity_socializer/db/dao/user_dao.py @@ -67,13 +67,13 @@ async def update_user_model( async def delete_user_model( self, - uid: str, + user_id: str, ) -> None: """Soft delete a single user to session.""" stmt = ( update(UserModel) - .where(UserModel.id == uid) + .where(UserModel.id == user_id) .values( blocked=True, ) diff --git a/identity_socializer/db/migrations/versions/2023-09-21-17-33_847eee4ea866.py b/identity_socializer/db/migrations/versions/2023-09-21-17-33_847eee4ea866.py index 58c3449..7ee9e02 100644 --- a/identity_socializer/db/migrations/versions/2023-09-21-17-33_847eee4ea866.py +++ b/identity_socializer/db/migrations/versions/2023-09-21-17-33_847eee4ea866.py @@ -27,6 +27,7 @@ def upgrade() -> None: sa.Column("bio_msg", sa.String(length=200), nullable=True), sa.Column("profile_photo_id", sa.String(length=200), nullable=True), sa.Column("blocked", sa.Boolean(), nullable=False, default=False), + sa.Column("created_at", sa.DateTime(), nullable=False), sa.PrimaryKeyConstraint("id"), ) # ### end Alembic commands ### diff --git a/identity_socializer/db/models/user_model.py b/identity_socializer/db/models/user_model.py index 889ca37..3ec35c8 100644 --- a/identity_socializer/db/models/user_model.py +++ b/identity_socializer/db/models/user_model.py @@ -1,3 +1,6 @@ +import datetime + +from sqlalchemy import DATETIME from sqlalchemy.orm import Mapped, mapped_column from sqlalchemy.sql.sqltypes import Boolean, String @@ -19,3 +22,8 @@ class UserModel(Base): bio_msg: Mapped[str] = mapped_column(String(length), nullable=True) profile_photo_id: Mapped[str] = mapped_column(String(length), nullable=True) blocked: Mapped[bool] = mapped_column(Boolean, nullable=False, default=False) + created_at: Mapped[DATETIME] = mapped_column( + DATETIME, + default=datetime.datetime.utcnow(), + nullable=False, + ) diff --git a/identity_socializer/web/api/auth/schema.py b/identity_socializer/web/api/auth/schema.py index e90ab06..7d2377a 100644 --- a/identity_socializer/web/api/auth/schema.py +++ b/identity_socializer/web/api/auth/schema.py @@ -36,10 +36,3 @@ class SimpleUserModelDTO(BaseModel): name: str email: str model_config = ConfigDict(from_attributes=True) - - -class IdUserModel(BaseModel): - """Message model for requests with user id.""" - - id: str - model_config = ConfigDict(from_attributes=True) diff --git a/identity_socializer/web/api/auth/views.py b/identity_socializer/web/api/auth/views.py index e218aef..974cf7d 100644 --- a/identity_socializer/web/api/auth/views.py +++ b/identity_socializer/web/api/auth/views.py @@ -6,7 +6,6 @@ from identity_socializer.db.dao.user_dao import UserDAO from identity_socializer.db.models.user_model import UserModel from identity_socializer.web.api.auth.schema import ( - IdUserModel, SecurityToken, SimpleUserModelDTO, Success, @@ -66,15 +65,13 @@ async def update_user( ) -@router.put("/delete_user", response_model=None) +@router.put("/delete_user/{user_id}", response_model=None) async def delete_user( - user: IdUserModel, + user_id: str, user_dao: UserDAO = Depends(), ) -> None: - """Update a user.""" - await user_dao.delete_user_model( - uid=user.id, - ) + """Block a single user.""" + await user_dao.delete_user_model(user_id) @router.get("/users", response_model=List[UserModelDTO])