mirror of
https://github.com/Monadical-SAS/reflector.git
synced 2025-12-20 20:29:06 +00:00
server: update get_all to filter empty and unfinished transcripts
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user