41 lines
959 B
Python
Executable File
41 lines
959 B
Python
Executable File
from __future__ import annotations
|
|
|
|
import uuid
|
|
from datetime import datetime
|
|
|
|
from pydantic import BaseModel, ConfigDict
|
|
|
|
|
|
class SongCommentCreate(BaseModel):
|
|
body: str
|
|
timestamp: float | None = None
|
|
tag: str | None = None
|
|
|
|
|
|
class SongCommentRead(BaseModel):
|
|
model_config = ConfigDict(from_attributes=True)
|
|
|
|
id: uuid.UUID
|
|
song_id: uuid.UUID
|
|
body: str
|
|
author_id: uuid.UUID
|
|
author_name: str
|
|
author_avatar_url: str | None
|
|
timestamp: float | None
|
|
tag: str | None
|
|
created_at: datetime
|
|
|
|
@classmethod
|
|
def from_model(cls, c: object) -> SongCommentRead:
|
|
return cls(
|
|
id=c.id,
|
|
song_id=c.song_id,
|
|
body=c.body,
|
|
author_id=c.author_id,
|
|
author_name=c.author.display_name,
|
|
author_avatar_url=c.author.avatar_url,
|
|
timestamp=c.timestamp,
|
|
tag=getattr(c, "tag", None),
|
|
created_at=c.created_at,
|
|
)
|