WIP: Add timestamp to comments and fix frontend errors
This commit is contained in:
22
api/alembic/versions/0005_add_timestamp_to_song_comments.py
Normal file
22
api/alembic/versions/0005_add_timestamp_to_song_comments.py
Normal file
@@ -0,0 +1,22 @@
|
||||
"""Add timestamp to song_comments.
|
||||
|
||||
Revision ID: 0005
|
||||
Revises: 0004
|
||||
Create Date: 2026-03-29
|
||||
"""
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
revision = "0005"
|
||||
down_revision = "0004"
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
op.add_column("song_comments", sa.Column("timestamp", sa.Float(), nullable=True))
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
op.drop_column("song_comments", "timestamp")
|
||||
@@ -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