Merge pull request #166 from presenton/fix/db-issues

fix(fastapi): all returning presentation with no slides
This commit is contained in:
Saurav Niraula 2025-07-30 10:10:16 +05:45 committed by GitHub
commit 8ec1f0cea6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 5 additions and 10 deletions

View file

@ -5,7 +5,7 @@ import random
from typing import Annotated, List, Literal, Optional
from fastapi import APIRouter, Body, Depends, File, HTTPException, UploadFile
from fastapi.responses import StreamingResponse
from sqlalchemy import String, cast, delete, text
from sqlalchemy import String, cast, delete
from sqlalchemy.ext.asyncio import AsyncSession
from sqlmodel import select
from constants.documents import UPLOAD_ACCEPTED_FILE_TYPES
@ -81,23 +81,19 @@ async def delete_presentation(
@PRESENTATION_ROUTER.get("/all", response_model=List[PresentationWithSlides])
async def get_all_presentations(sql_session: AsyncSession = Depends(get_async_session)):
presentations_with_slides = []
presentations = await sql_session.scalars(
select(PresentationModel).where(
cast(PresentationModel.layout, String) != "null"
)
)
presentations = await sql_session.scalars(select(PresentationModel))
async def inner(presentation: PresentationModel, sql_session: AsyncSession):
slides = await sql_session.scalars(
first_slide = await sql_session.scalar(
select(SlideModel)
.where(SlideModel.presentation == presentation.id)
.where(SlideModel.index == 0)
)
if not slides:
if not first_slide:
return None
return PresentationWithSlides(
**presentation.model_dump(),
slides=slides,
slides=[first_slide],
)
tasks = [inner(p, sql_session) for p in presentations]

View file

@ -93,7 +93,6 @@ pycparser==2.22
pydantic==2.11.7
pydantic_core==2.33.2
Pygments==2.19.2
PyMySQL==1.1.1
pypdfium2==4.30.1
PyPika==0.48.9
pyproject_hooks==1.2.0