Add Pydantic models and FastAPI router structure for agent and backend
CI / basic-check (push) Has been cancelled
CI / basic-check (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
from fastapi import APIRouter, HTTPException
|
||||
|
||||
from app.schemas import DiscoveryRun, EntityResponse, ListResponse
|
||||
from app.services.store import DISCOVERY_RUNS
|
||||
|
||||
router = APIRouter(prefix='/discoveries', tags=['discoveries'])
|
||||
|
||||
|
||||
@router.get('', response_model=ListResponse[DiscoveryRun])
|
||||
def list_discoveries() -> ListResponse[DiscoveryRun]:
|
||||
return ListResponse(count=len(DISCOVERY_RUNS), items=DISCOVERY_RUNS)
|
||||
|
||||
|
||||
@router.get('/{discovery_id}', response_model=EntityResponse[DiscoveryRun])
|
||||
def get_discovery(discovery_id: str) -> EntityResponse[DiscoveryRun]:
|
||||
for item in DISCOVERY_RUNS:
|
||||
if item.id == discovery_id:
|
||||
return EntityResponse(item=item)
|
||||
raise HTTPException(status_code=404, detail='Discovery not found')
|
||||
@@ -0,0 +1,35 @@
|
||||
import time
|
||||
from datetime import datetime, timezone
|
||||
|
||||
from fastapi import APIRouter
|
||||
|
||||
from app.schemas import HealthCheck, HealthResponse
|
||||
|
||||
router = APIRouter(tags=['health'])
|
||||
START_TIME = time.time()
|
||||
|
||||
|
||||
def build_health() -> HealthResponse:
|
||||
return HealthResponse(
|
||||
status='pass',
|
||||
service='netmapper-backend',
|
||||
version='0.1.0',
|
||||
time=datetime.now(timezone.utc),
|
||||
uptime_s=round(time.time() - START_TIME, 2),
|
||||
checks={'db': HealthCheck(status='warn', detail='database not configured yet')},
|
||||
)
|
||||
|
||||
|
||||
@router.get('/live', response_model=HealthResponse)
|
||||
def live() -> HealthResponse:
|
||||
return build_health()
|
||||
|
||||
|
||||
@router.get('/ready', response_model=HealthResponse)
|
||||
def ready() -> HealthResponse:
|
||||
return build_health()
|
||||
|
||||
|
||||
@router.get('/health', response_model=HealthResponse)
|
||||
def health() -> HealthResponse:
|
||||
return build_health()
|
||||
@@ -0,0 +1,19 @@
|
||||
from fastapi import APIRouter, HTTPException
|
||||
|
||||
from app.schemas import EntityResponse, Job, ListResponse
|
||||
from app.services.store import JOBS
|
||||
|
||||
router = APIRouter(prefix='/jobs', tags=['jobs'])
|
||||
|
||||
|
||||
@router.get('', response_model=ListResponse[Job])
|
||||
def list_jobs() -> ListResponse[Job]:
|
||||
return ListResponse(count=len(JOBS), items=JOBS)
|
||||
|
||||
|
||||
@router.get('/{job_id}', response_model=EntityResponse[Job])
|
||||
def get_job(job_id: str) -> EntityResponse[Job]:
|
||||
for item in JOBS:
|
||||
if item.id == job_id:
|
||||
return EntityResponse(item=item)
|
||||
raise HTTPException(status_code=404, detail='Job not found')
|
||||
@@ -0,0 +1,19 @@
|
||||
from fastapi import APIRouter, HTTPException
|
||||
|
||||
from app.schemas import EntityResponse, ListResponse, NetObject
|
||||
from app.services.store import OBJECTS
|
||||
|
||||
router = APIRouter(prefix='/objects', tags=['objects'])
|
||||
|
||||
|
||||
@router.get('', response_model=ListResponse[NetObject])
|
||||
def list_objects() -> ListResponse[NetObject]:
|
||||
return ListResponse(count=len(OBJECTS), items=OBJECTS)
|
||||
|
||||
|
||||
@router.get('/{object_id}', response_model=EntityResponse[NetObject])
|
||||
def get_object(object_id: str) -> EntityResponse[NetObject]:
|
||||
for item in OBJECTS:
|
||||
if item.id == object_id:
|
||||
return EntityResponse(item=item)
|
||||
raise HTTPException(status_code=404, detail='Object not found')
|
||||
Reference in New Issue
Block a user