Fix: Load user relationship in listings API to prevent 500 error
Some checks failed
CI / Frontend Lint & Type Check (push) Has been cancelled
CI / Frontend Build (push) Has been cancelled
CI / Backend Lint (push) Has been cancelled
CI / Backend Tests (push) Has been cancelled
CI / Docker Build (push) Has been cancelled
CI / Security Scan (push) Has been cancelled
Deploy / Build & Push Images (push) Has been cancelled
Deploy / Deploy to Server (push) Has been cancelled
Deploy / Notify (push) Has been cancelled
Some checks failed
CI / Frontend Lint & Type Check (push) Has been cancelled
CI / Frontend Build (push) Has been cancelled
CI / Backend Lint (push) Has been cancelled
CI / Backend Tests (push) Has been cancelled
CI / Docker Build (push) Has been cancelled
CI / Security Scan (push) Has been cancelled
Deploy / Build & Push Images (push) Has been cancelled
Deploy / Deploy to Server (push) Has been cancelled
Deploy / Notify (push) Has been cancelled
This commit is contained in:
@ -27,6 +27,7 @@ from fastapi import APIRouter, Depends, Query, HTTPException, Request
|
|||||||
from pydantic import BaseModel, Field, EmailStr
|
from pydantic import BaseModel, Field, EmailStr
|
||||||
from sqlalchemy import select, func, and_
|
from sqlalchemy import select, func, and_
|
||||||
from sqlalchemy.ext.asyncio import AsyncSession
|
from sqlalchemy.ext.asyncio import AsyncSession
|
||||||
|
from sqlalchemy.orm import selectinload
|
||||||
|
|
||||||
from app.database import get_db
|
from app.database import get_db
|
||||||
from app.api.deps import get_current_user, get_current_user_optional
|
from app.api.deps import get_current_user, get_current_user_optional
|
||||||
@ -284,7 +285,7 @@ async def browse_listings(
|
|||||||
db: AsyncSession = Depends(get_db),
|
db: AsyncSession = Depends(get_db),
|
||||||
):
|
):
|
||||||
"""Browse active domain listings (public)."""
|
"""Browse active domain listings (public)."""
|
||||||
query = select(DomainListing).where(
|
query = select(DomainListing).options(selectinload(DomainListing.user)).where(
|
||||||
DomainListing.status == ListingStatus.ACTIVE.value
|
DomainListing.status == ListingStatus.ACTIVE.value
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -413,7 +414,9 @@ async def get_listing_by_slug(
|
|||||||
):
|
):
|
||||||
"""Get listing details by slug (public)."""
|
"""Get listing details by slug (public)."""
|
||||||
result = await db.execute(
|
result = await db.execute(
|
||||||
select(DomainListing).where(
|
select(DomainListing)
|
||||||
|
.options(selectinload(DomainListing.user))
|
||||||
|
.where(
|
||||||
and_(
|
and_(
|
||||||
DomainListing.slug == slug,
|
DomainListing.slug == slug,
|
||||||
DomainListing.status == ListingStatus.ACTIVE.value,
|
DomainListing.status == ListingStatus.ACTIVE.value,
|
||||||
|
|||||||
Reference in New Issue
Block a user