first commit

This commit is contained in:
VPN SaaS Dev
2026-05-12 03:52:13 +09:00
commit d93c88c751
44 changed files with 4108 additions and 0 deletions

21
app/api/catalog.py Normal file
View File

@@ -0,0 +1,21 @@
from fastapi import APIRouter, Depends
from sqlalchemy import select
from sqlalchemy.ext.asyncio import AsyncSession
from sqlalchemy.orm import selectinload
from app.db.session import get_session
from app.models.car import CarMake
from app.schemas.car import CarMakeRead
router = APIRouter(prefix="/catalog", tags=["catalog"])
@router.get("/makes", response_model=list[CarMakeRead])
async def list_makes(session: AsyncSession = Depends(get_session)) -> list[CarMake]:
result = await session.execute(
select(CarMake).options(selectinload(CarMake.models)).order_by(CarMake.name)
)
makes = list(result.scalars())
for make in makes:
make.models.sort(key=lambda model: model.name)
return makes