Skip to content

Commit

Permalink
added birthdate and gender fields for user.
Browse files Browse the repository at this point in the history
  • Loading branch information
justintroy committed Dec 4, 2023
1 parent 0df0f0a commit 3423f9e
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
"""Added birthdate and gender to users table.
Revision ID: 669a669eb646
Revises: b949ec822291
Create Date: 2023-12-04 12:20:10.999671
"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '669a669eb646'
down_revision = 'b949ec822291'
branch_labels = None
depends_on = None


def upgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.drop_constraint('forgot_password_identifier_key', 'forgot_password', type_='unique')
op.add_column('users', sa.Column('birthdate', sa.DateTime(), nullable=True))
op.add_column('users', sa.Column('gender', sa.Text(), nullable=True))
# ### end Alembic commands ###


def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.drop_column('users', 'gender')
op.drop_column('users', 'birthdate')
op.create_unique_constraint('forgot_password_identifier_key', 'forgot_password', ['identifier'])
# ### end Alembic commands ###
10 changes: 10 additions & 0 deletions app/api/user/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ def create_user(db: Session, user: UserCreate) -> User:
id=user.id or str(uuid.uuid4()),
username=user.username,
email=user.email,
gender=user.gender,
birthdate=user.birthdate,
password=hashed_password,
created_at=datetime.utcnow(),
deleted_at=None,
Expand All @@ -52,6 +54,14 @@ def update_user(db: Session, user: User, user_update: UserUpdate) -> User:
return user


def update_user_password(db: Session, user: User, password: str) -> User:
user.password = password
user.updated_at = datetime.utcnow()
db.commit()
db.refresh(user)
return user


def delete_user(db: Session, user: User) -> User:
user.deleted_at = datetime.utcnow()
db.commit()
Expand Down
2 changes: 2 additions & 0 deletions app/api/user/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
class UserBase(BaseModel):
username: str
email: str
birthdate: datetime
gender: str


class UserCreate(UserBase):
Expand Down
2 changes: 2 additions & 0 deletions app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ class User(Base):
username = Column(Text, unique=True, nullable=False)
email = Column(Text, primary_key=True, unique=True, nullable=False)
password = Column(Text, nullable=False)
birthdate = Column(DateTime, nullable=True)
gender = Column(Text, nullable=True)


class ForgotPassword(Base):
Expand Down

0 comments on commit 3423f9e

Please sign in to comment.