33 lines
1.0 KiB
Python
Executable File
33 lines
1.0 KiB
Python
Executable File
from __future__ import annotations
|
|
|
|
import uuid
|
|
|
|
from sqlalchemy import select
|
|
from sqlalchemy.orm import selectinload
|
|
|
|
from rehearsalhub.db.models import SongComment
|
|
from rehearsalhub.repositories.base import BaseRepository
|
|
|
|
|
|
class CommentRepository(BaseRepository[SongComment]):
|
|
model = SongComment
|
|
|
|
async def list_for_song(self, song_id: uuid.UUID) -> list[SongComment]:
|
|
stmt = (
|
|
select(SongComment)
|
|
.options(selectinload(SongComment.author))
|
|
.where(SongComment.song_id == song_id)
|
|
.order_by(SongComment.created_at)
|
|
)
|
|
result = await self.session.execute(stmt)
|
|
return list(result.scalars().all())
|
|
|
|
async def get_with_author(self, comment_id: uuid.UUID) -> SongComment | None:
|
|
stmt = (
|
|
select(SongComment)
|
|
.options(selectinload(SongComment.author))
|
|
.where(SongComment.id == comment_id)
|
|
)
|
|
result = await self.session.execute(stmt)
|
|
return result.scalar_one_or_none()
|