Skip to content

Commit

Permalink
Merge pull request #8 from bambu-group-03/feature/first-user-registra…
Browse files Browse the repository at this point in the history
…tion

First user model

closes #17
  • Loading branch information
LuisCusihuaman authored Oct 15, 2023
2 parents b60fa7d + bfe0206 commit 43fb993
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 29 deletions.
10 changes: 5 additions & 5 deletions identity_socializer/db/dao/user_dao.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@ async def create_user_model(
self,
uid: str,
email: str,
first_name: str,
last_name: str,
phone_number: str,
bio_msg: str,
first_name: Optional[str] = None,
last_name: Optional[str] = None,
phone_number: Optional[str] = None,
bio_msg: Optional[str] = None,
) -> None:

"""
Add single user to session.
:param name: name of a user.
It could contain only id and email.
"""
user_model = UserModel(
first_name=first_name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def upgrade() -> None:
sa.Column("first_name", sa.String(length=50), nullable=True),
sa.Column("last_name", sa.String(length=50), nullable=True),
sa.Column("phone_number", sa.String(length=20), nullable=True),
sa.Column("email", sa.String(length=50), nullable=True),
sa.Column("email", sa.String(length=50), nullable=False),
sa.Column("bio_msg", sa.String(length=200), nullable=True),
sa.Column("profile_photo_id", sa.String(length=200), nullable=True),
sa.PrimaryKeyConstraint("id"),
Expand Down
10 changes: 5 additions & 5 deletions identity_socializer/db/models/user_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ class UserModel(Base):

id: Mapped[str] = mapped_column(primary_key=True)
email: Mapped[str] = mapped_column(String(length))
first_name: Mapped[str] = mapped_column(String(length))
last_name: Mapped[str] = mapped_column(String(length))
phone_number: Mapped[str] = mapped_column(String(length))
bio_msg: Mapped[str] = mapped_column(String(length))
profile_photo_id: Mapped[str] = mapped_column(String(length))
first_name: Mapped[str] = mapped_column(String(length), nullable=True)
last_name: Mapped[str] = mapped_column(String(length), nullable=True)
phone_number: Mapped[str] = mapped_column(String(length), nullable=True)
bio_msg: Mapped[str] = mapped_column(String(length), nullable=True)
profile_photo_id: Mapped[str] = mapped_column(String(length), nullable=True)
19 changes: 15 additions & 4 deletions identity_socializer/web/api/auth/schema.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import Optional

from pydantic import BaseModel, ConfigDict


Expand All @@ -18,8 +20,17 @@ class UserModelDTO(BaseModel):

id: str
email: str
first_name: str
last_name: str
phone_number: str
bio_msg: str
first_name: Optional[str]
last_name: Optional[str]
phone_number: Optional[str]
bio_msg: Optional[str]
model_config = ConfigDict(from_attributes=True)


class SimpleUserModelDTO(BaseModel):
"""Message model for user register."""

id: str
name: str
email: str
model_config = ConfigDict(from_attributes=True)
24 changes: 10 additions & 14 deletions identity_socializer/web/api/auth/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@

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 SecurityToken, Success, UserModelDTO
from identity_socializer.web.api.auth.schema import (
SecurityToken,
SimpleUserModelDTO,
Success,
UserModelDTO,
)

router = APIRouter()

Expand Down Expand Up @@ -34,22 +39,13 @@ async def signup(

@router.post("/register", response_model=None)
async def register(
incoming_message: UserModelDTO,
simple_user: SimpleUserModelDTO,
user_dao: UserDAO = Depends(),
) -> None:
"""
Register a user.
:param incoming_message: Incoming message.
:param user_dao: DAO for users models.
"""
"""Register a user with minimal information."""
await user_dao.create_user_model(
uid=incoming_message.id,
first_name=incoming_message.first_name,
last_name=incoming_message.last_name,
phone_number=incoming_message.phone_number,
bio_msg=incoming_message.bio_msg,
email=incoming_message.email,
uid=simple_user.id,
email=simple_user.email,
)


Expand Down

0 comments on commit 43fb993

Please sign in to comment.