24 lines
1.0 KiB
Python
24 lines
1.0 KiB
Python
from fastapi import APIRouter, Depends, HTTPException
|
|
from sqlalchemy.ext.asyncio import AsyncSession
|
|
from sqlalchemy import select
|
|
from typing import List
|
|
from app.database import get_db
|
|
from app.models import JobExecution
|
|
from app.schemas import JobExecution as JobExecutionSchema
|
|
|
|
router = APIRouter(prefix="/api/executions", tags=["executions"])
|
|
|
|
@router.get("/", response_model=List[JobExecutionSchema])
|
|
async def list_executions(db: AsyncSession = Depends(get_db)):
|
|
result = await db.execute(select(JobExecution).order_by(JobExecution.started_at.desc()))
|
|
executions = result.scalars().all()
|
|
return executions
|
|
|
|
@router.get("/{execution_id}", response_model=JobExecutionSchema)
|
|
async def get_execution(execution_id: int, db: AsyncSession = Depends(get_db)):
|
|
result = await db.execute(select(JobExecution).where(JobExecution.id == execution_id))
|
|
execution = result.scalar_one_or_none()
|
|
if not execution:
|
|
raise HTTPException(status_code=404, detail="Execution not found")
|
|
return execution
|