27 lines
933 B
Python
27 lines
933 B
Python
"""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()]
|
|
|