server: update get_all to filter empty and unfinished transcripts

This commit is contained in:
2023-10-13 09:57:28 +02:00
committed by Mathieu Virbel
parent a5b9e75e21
commit a3e9683f1e

View File

@@ -153,8 +153,27 @@ class Transcript(BaseModel):
class TranscriptController:
async def get_all(self, user_id: str | None = None) -> list[Transcript]:
async def get_all(
self,
user_id: str | None = None,
order_by: str | None = None,
filter_empty: bool | None = True,
filter_recording: bool | None = True,
) -> list[Transcript]:
query = transcripts.select().where(transcripts.c.user_id == user_id)
if order_by is not None:
field = getattr(transcripts.c, order_by[1:])
if order_by.startswith("-"):
field = field.desc()
query = query.order_by(field)
if filter_empty:
query = query.filter(transcripts.c.status != "idle")
if filter_recording:
query = query.filter(transcripts.c.status != "recording")
results = await database.fetch_all(query)
return results
@@ -225,8 +244,8 @@ class GetTranscript(BaseModel):
short_summary: str | None
long_summary: str | None
created_at: datetime
source_language: str
target_language: str
source_language: str | None
target_language: str | None
class CreateTranscript(BaseModel):
@@ -255,7 +274,9 @@ async def transcripts_list(
raise HTTPException(status_code=401, detail="Not authenticated")
user_id = user["sub"] if user else None
return paginate(await transcripts_controller.get_all(user_id=user_id))
return paginate(
await transcripts_controller.get_all(user_id=user_id, order_by="-created_at")
)
@router.post("/transcripts", response_model=GetTranscript)