Skip to content

Commit

Permalink
Add a balance to user
Browse files Browse the repository at this point in the history
  • Loading branch information
Your Name committed Dec 22, 2024
1 parent b82c104 commit 254108c
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
2 changes: 2 additions & 0 deletions back/app/commands/reset_db.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/local/bin/python

from datetime import timedelta
from decimal import Decimal

from alembic import command
from alembic.config import Config
Expand Down Expand Up @@ -90,6 +91,7 @@ def seed_db(session: Session) -> None:
phone_number=PhoneNumber("06 62102508"),
email="DaviD@mail.com",
password=SecretStr("azerty123"),
balance=Decimal("3.40"),
),
session=session,
)
Expand Down
2 changes: 2 additions & 0 deletions back/app/models/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from app.models.base import MyModel, SecretIdModel
from app.schemas.token import AccessJWT
from app.schemas.user import UserClassicIn, UserLinkedinIn
from app.utils.fields import Price

if TYPE_CHECKING:
from app.models.badge import Badge
Expand All @@ -26,6 +27,7 @@ class User(SecretIdModel, MyModel):
first_name: Mapped[str | None]
last_name: Mapped[str | None]
phone_number: Mapped[str | None]
balance: Mapped[Price | None]
badges: Mapped[list[Badge]] = relationship(back_populates="owner")
hashed_password: Mapped[str | None] = mapped_column(default=None)
linkedin_id: Mapped[str | None] = mapped_column(index=True, unique=True, default=None)
Expand Down
5 changes: 4 additions & 1 deletion back/app/schemas/user.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
from decimal import Decimal

from pydantic import EmailStr, Field, computed_field, field_validator

from app.schemas.base import MySchema, PhoneNumberSchemaIn, PhoneNumberSchemaOut
from app.utils.fields import Password
from app.utils.fields import Password, Price
from app.utils.strings import SecretId


class UserBaseIn(PhoneNumberSchemaIn):
email: EmailStr
first_name: str = Field(min_length=1, max_length=128)
last_name: str = Field(min_length=1, max_length=128)
balance: Price = Decimal(0)

@field_validator("email", mode="before")
def normalize_email(cls, value: str) -> str:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"""initial
Revision ID: ac6b8f436272
Revision ID: 36d891fb1a72
Revises:
Create Date: 2024-12-21 12:03:13.116537+01:00
Create Date: 2024-12-22 12:44:52.480268+01:00
"""

Expand All @@ -13,7 +13,7 @@
from sqlalchemy.dialects import postgresql

# revision identifiers, used by Alembic.
revision: str = "ac6b8f436272"
revision: str = "36d891fb1a72"
down_revision: str | None = None
branch_labels: str | Sequence[str] | None = None
depends_on: str | Sequence[str] | None = None
Expand Down Expand Up @@ -59,6 +59,7 @@ def upgrade() -> None:
sa.Column("first_name", sa.String(), nullable=True),
sa.Column("last_name", sa.String(), nullable=True),
sa.Column("phone_number", sa.String(), nullable=True),
sa.Column("balance", sa.Numeric(), nullable=True),
sa.Column("hashed_password", sa.String(), nullable=True),
sa.Column("linkedin_id", sa.String(), nullable=True),
sa.Column("is_superuser", sa.Boolean(), nullable=False),
Expand Down

0 comments on commit 254108c

Please sign in to comment.