Skip to content

Commit

Permalink
added created_at to user model
Browse files Browse the repository at this point in the history
  • Loading branch information
noxethiems committed Oct 16, 2023
1 parent 53613e0 commit bfb0d9f
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 16 deletions.
4 changes: 2 additions & 2 deletions identity_socializer/db/dao/user_dao.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 ###
Expand Down
8 changes: 8 additions & 0 deletions identity_socializer/db/models/user_model.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import datetime

from sqlalchemy import DATETIME
from sqlalchemy.orm import Mapped, mapped_column
from sqlalchemy.sql.sqltypes import Boolean, String

Expand All @@ -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,
)
7 changes: 0 additions & 7 deletions identity_socializer/web/api/auth/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
11 changes: 4 additions & 7 deletions identity_socializer/web/api/auth/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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])
Expand Down

0 comments on commit bfb0d9f

Please sign in to comment.