WIP: Add timestamp to comments and fix frontend errors
This commit is contained in:
@@ -206,6 +206,7 @@ class SongComment(Base):
|
||||
UUID(as_uuid=True), ForeignKey("members.id", ondelete="CASCADE"), nullable=False
|
||||
)
|
||||
body: Mapped[str] = mapped_column(Text, nullable=False)
|
||||
timestamp: Mapped[Optional[float]] = mapped_column(Numeric(10, 2), nullable=True)
|
||||
created_at: Mapped[datetime] = mapped_column(
|
||||
DateTime(timezone=True), server_default=func.now(), nullable=False
|
||||
)
|
||||
|
||||
@@ -264,7 +264,7 @@ async def create_comment(
|
||||
):
|
||||
await _assert_song_membership(song_id, current_member.id, session)
|
||||
repo = CommentRepository(session)
|
||||
comment = await repo.create(song_id=song_id, author_id=current_member.id, body=data.body)
|
||||
comment = await repo.create(song_id=song_id, author_id=current_member.id, body=data.body, timestamp=data.timestamp)
|
||||
comment = await repo.get_with_author(comment.id)
|
||||
return SongCommentRead.from_model(comment)
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ from pydantic import BaseModel, ConfigDict
|
||||
|
||||
class SongCommentCreate(BaseModel):
|
||||
body: str
|
||||
timestamp: float | None = None
|
||||
|
||||
|
||||
class SongCommentRead(BaseModel):
|
||||
@@ -18,6 +19,7 @@ class SongCommentRead(BaseModel):
|
||||
body: str
|
||||
author_id: uuid.UUID
|
||||
author_name: str
|
||||
timestamp: float | None
|
||||
created_at: datetime
|
||||
|
||||
@classmethod
|
||||
@@ -28,5 +30,6 @@ class SongCommentRead(BaseModel):
|
||||
body=getattr(c, "body"),
|
||||
author_id=getattr(c, "author_id"),
|
||||
author_name=getattr(getattr(c, "author"), "display_name"),
|
||||
timestamp=getattr(c, "timestamp"),
|
||||
created_at=getattr(c, "created_at"),
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user