Implement FastAPI Temporal MVP pipeline
This commit is contained in:
26
app/application/services/asset_service.py
Normal file
26
app/application/services/asset_service.py
Normal file
@@ -0,0 +1,26 @@
|
||||
"""Asset application service."""
|
||||
|
||||
from fastapi import HTTPException, status
|
||||
from sqlalchemy import select
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from app.api.schemas.asset import AssetRead
|
||||
from app.infra.db.models.asset import AssetORM
|
||||
from app.infra.db.models.order import OrderORM
|
||||
|
||||
|
||||
class AssetService:
|
||||
"""Application service for asset queries."""
|
||||
|
||||
async def list_order_assets(self, session: AsyncSession, order_id: int) -> list[AssetRead]:
|
||||
"""Return all assets belonging to an order."""
|
||||
|
||||
order = await session.get(OrderORM, order_id)
|
||||
if order is None:
|
||||
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Order not found")
|
||||
|
||||
result = await session.execute(
|
||||
select(AssetORM).where(AssetORM.order_id == order_id).order_by(AssetORM.created_at.asc())
|
||||
)
|
||||
return [AssetRead.model_validate(asset) for asset in result.scalars().all()]
|
||||
|
||||
Reference in New Issue
Block a user