- Created a new test package for services and added tests for AuthService. - Implemented tests for user registration, login, and token creation. - Added a new test package for utilities and included tests for password and JWT utilities. - Updated `uv.lock` to include new dependencies: bcrypt, email-validator, pyjwt, and pytest-asyncio.
38 lines
1.4 KiB
Python
38 lines
1.4 KiB
Python
from datetime import datetime
|
|
from typing import TYPE_CHECKING
|
|
|
|
from sqlmodel import Field, Relationship
|
|
|
|
from app.models.base import BaseModel
|
|
|
|
if TYPE_CHECKING:
|
|
from app.models.plan import Plan
|
|
from app.models.playlist import Playlist
|
|
from app.models.sound_played import SoundPlayed
|
|
from app.models.stream import Stream
|
|
from app.models.user_oauth import UserOauth
|
|
|
|
|
|
class User(BaseModel, table=True):
|
|
"""Database model for a user."""
|
|
|
|
plan_id: int = Field(foreign_key="plan.id")
|
|
role: str = Field(nullable=False, default="user")
|
|
email: str = Field(unique=True, nullable=False)
|
|
name: str = Field(nullable=False)
|
|
picture: str | None = Field(default=None)
|
|
password_hash: str | None = Field(default=None)
|
|
is_active: bool = Field(nullable=False, default=True)
|
|
credits: int = Field(default=0, ge=0, nullable=False)
|
|
api_token: str | None = Field(unique=True, default=None)
|
|
api_token_expires_at: datetime | None = Field(default=None)
|
|
refresh_token_hash: str | None = Field(default=None)
|
|
refresh_token_expires_at: datetime | None = Field(default=None)
|
|
|
|
# relationships
|
|
oauths: list["UserOauth"] = Relationship(back_populates="user")
|
|
plan: "Plan" = Relationship(back_populates="users")
|
|
playlists: list["Playlist"] = Relationship(back_populates="user")
|
|
sounds_played: list["SoundPlayed"] = Relationship(back_populates="user")
|
|
streams: list["Stream"] = Relationship(back_populates="user")
|