feat: Create Favorite model and repository for managing user favorites in the database feat: Add FavoriteService to handle business logic for favorites management feat: Enhance Playlist and Sound response schemas to include favorite indicators and counts refactor: Update API routes to include favorites functionality in playlists and sounds
42 lines
1.7 KiB
Python
42 lines
1.7 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.credit_transaction import CreditTransaction
|
|
from app.models.extraction import Extraction
|
|
from app.models.favorite import Favorite
|
|
from app.models.plan import Plan
|
|
from app.models.playlist import Playlist
|
|
from app.models.sound_played import SoundPlayed
|
|
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")
|
|
extractions: list["Extraction"] = Relationship(back_populates="user")
|
|
credit_transactions: list["CreditTransaction"] = Relationship(back_populates="user")
|
|
favorites: list["Favorite"] = Relationship(back_populates="user")
|