a89c7894cf
Backend: - FastAPI avec PostgreSQL et Redis - Authentification JWT complète - API REST pour musique, playlists, recherche - Streaming audio via yt-dlp - SQLAlchemy 2.0 async Frontend: - Flutter avec thème néon cyberpunk - State management Riverpod - Layout adaptatif desktop/mobile - Lecteur audio avec mini-player Infrastructure: - Docker Compose (PostgreSQL + Redis) - Scripts d'installation automatisés - Scripts de build pour exécutables Fichiers ajoutés: - BUILD_CLIENT_*.bat/sh: Scripts de compilation - BUILD_CLIENT_README.md: Documentation compilation - CHECK_FLUTTER.sh: Vérificateur d'environnement - requirements.txt mis à jour pour Python 3.13 - Modèles SQLAlchemy corrigés (metadata -> extra_metadata) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
122 lines
3.1 KiB
Python
122 lines
3.1 KiB
Python
"""Album model."""
|
|
import uuid
|
|
from datetime import datetime, date
|
|
from typing import TYPE_CHECKING
|
|
|
|
from sqlalchemy import String, Integer, DATE, ForeignKey
|
|
from sqlalchemy.dialects.postgresql import UUID, JSONB
|
|
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
|
|
|
from app.core.database import Base
|
|
|
|
if TYPE_CHECKING:
|
|
from app.models.artist import Artist
|
|
from app.models.track import Track
|
|
|
|
|
|
class Album(Base):
|
|
"""Album model representing music albums."""
|
|
|
|
__tablename__ = "albums"
|
|
|
|
# Primary key
|
|
id: Mapped[uuid.UUID] = mapped_column(
|
|
UUID(as_uuid=True),
|
|
primary_key=True,
|
|
default=uuid.uuid4,
|
|
index=True,
|
|
)
|
|
|
|
# Basic info
|
|
title: Mapped[str] = mapped_column(
|
|
String(255),
|
|
nullable=False,
|
|
index=True,
|
|
)
|
|
release_date: Mapped[date | None] = mapped_column(
|
|
DATE,
|
|
)
|
|
image_url: Mapped[str | None] = mapped_column(
|
|
String(500),
|
|
)
|
|
|
|
# Album details
|
|
total_tracks: Mapped[int] = mapped_column(
|
|
Integer,
|
|
default=0,
|
|
)
|
|
genre: Mapped[str | None] = mapped_column(
|
|
String(100),
|
|
)
|
|
|
|
# Foreign key to artist
|
|
artist_id: Mapped[uuid.UUID | None] = mapped_column(
|
|
UUID(as_uuid=True),
|
|
ForeignKey("artists.id", ondelete="CASCADE"),
|
|
nullable=True,
|
|
index=True,
|
|
)
|
|
|
|
# External IDs
|
|
spotify_id: Mapped[str | None] = mapped_column(
|
|
String(100),
|
|
unique=True,
|
|
index=True,
|
|
)
|
|
youtube_playlist_id: Mapped[str | None] = mapped_column(
|
|
String(100),
|
|
unique=True,
|
|
index=True,
|
|
)
|
|
|
|
# Additional metadata stored as JSON
|
|
extra_metadata: Mapped[dict] = mapped_column(
|
|
"metadata",
|
|
JSONB,
|
|
default=dict,
|
|
)
|
|
|
|
# Timestamps
|
|
created_at: Mapped[datetime] = mapped_column(
|
|
default=datetime.utcnow,
|
|
nullable=False,
|
|
)
|
|
updated_at: Mapped[datetime] = mapped_column(
|
|
default=datetime.utcnow,
|
|
onupdate=datetime.utcnow,
|
|
nullable=False,
|
|
)
|
|
|
|
# Relationships
|
|
artist: Mapped["Artist"] = relationship(
|
|
"Artist",
|
|
back_populates="albums",
|
|
lazy="selectin",
|
|
)
|
|
tracks: Mapped[list["Track"]] = relationship(
|
|
"Track",
|
|
back_populates="album",
|
|
cascade="all, delete-orphan",
|
|
lazy="selectin",
|
|
)
|
|
|
|
def __repr__(self) -> str:
|
|
return f"<Album {self.title}>"
|
|
|
|
def to_dict(self) -> dict:
|
|
"""Convert album model to dictionary."""
|
|
return {
|
|
"id": str(self.id),
|
|
"title": self.title,
|
|
"release_date": self.release_date.isoformat() if self.release_date else None,
|
|
"image_url": self.image_url,
|
|
"total_tracks": self.total_tracks,
|
|
"genre": self.genre,
|
|
"artist_id": str(self.artist_id) if self.artist_id else None,
|
|
"spotify_id": self.spotify_id,
|
|
"youtube_playlist_id": self.youtube_playlist_id,
|
|
"metadata": self.extra_metadata,
|
|
"created_at": self.created_at.isoformat(),
|
|
"updated_at": self.updated_at.isoformat(),
|
|
}
|