feat: Implement Text-to-Speech (TTS) functionality with API endpoints, models, and service integration
This commit is contained in:
62
app/repositories/tts.py
Normal file
62
app/repositories/tts.py
Normal file
@@ -0,0 +1,62 @@
|
||||
"""TTS repository for database operations."""
|
||||
|
||||
from typing import Any, Sequence
|
||||
|
||||
from sqlmodel import select
|
||||
|
||||
from app.models.tts import TTS
|
||||
from app.repositories.base import BaseRepository
|
||||
|
||||
|
||||
class TTSRepository(BaseRepository[TTS]):
|
||||
"""Repository for TTS operations."""
|
||||
|
||||
def __init__(self, session: Any) -> None:
|
||||
super().__init__(TTS, session)
|
||||
|
||||
async def get_by_user_id(
|
||||
self,
|
||||
user_id: int,
|
||||
limit: int = 50,
|
||||
offset: int = 0,
|
||||
) -> Sequence[TTS]:
|
||||
"""Get TTS records by user ID with pagination.
|
||||
|
||||
Args:
|
||||
user_id: User ID to filter by
|
||||
limit: Maximum number of records to return
|
||||
offset: Number of records to skip
|
||||
|
||||
Returns:
|
||||
List of TTS records
|
||||
"""
|
||||
stmt = (
|
||||
select(self.model)
|
||||
.where(self.model.user_id == user_id)
|
||||
.order_by(self.model.created_at.desc())
|
||||
.limit(limit)
|
||||
.offset(offset)
|
||||
)
|
||||
result = await self.session.exec(stmt)
|
||||
return result.all()
|
||||
|
||||
async def get_by_user_and_id(
|
||||
self,
|
||||
user_id: int,
|
||||
tts_id: int,
|
||||
) -> TTS | None:
|
||||
"""Get a specific TTS record by user ID and TTS ID.
|
||||
|
||||
Args:
|
||||
user_id: User ID to filter by
|
||||
tts_id: TTS ID to retrieve
|
||||
|
||||
Returns:
|
||||
TTS record if found and belongs to user, None otherwise
|
||||
"""
|
||||
stmt = select(self.model).where(
|
||||
self.model.id == tts_id,
|
||||
self.model.user_id == user_id,
|
||||
)
|
||||
result = await self.session.exec(stmt)
|
||||
return result.first()
|
||||
Reference in New Issue
Block a user