Splits the three grouped router files into eight api_<verb>_<resource>.py modules under decnet/web/router/swarm/ to match the convention used by router/fleet/ and router/config/. Shared request/response models live in _schemas.py. Keeps each endpoint easy to locate and modify without stepping on siblings.
22 lines
694 B
Python
22 lines
694 B
Python
"""GET /swarm/hosts/{uuid} — fetch a single worker by UUID."""
|
|
from __future__ import annotations
|
|
|
|
from fastapi import APIRouter, Depends, HTTPException
|
|
|
|
from decnet.web.db.repository import BaseRepository
|
|
from decnet.web.dependencies import get_repo
|
|
from decnet.web.router.swarm._schemas import SwarmHostView
|
|
|
|
router = APIRouter()
|
|
|
|
|
|
@router.get("/hosts/{uuid}", response_model=SwarmHostView, tags=["Swarm Hosts"])
|
|
async def api_get_host(
|
|
uuid: str,
|
|
repo: BaseRepository = Depends(get_repo),
|
|
) -> SwarmHostView:
|
|
row = await repo.get_swarm_host_by_uuid(uuid)
|
|
if row is None:
|
|
raise HTTPException(status_code=404, detail="host not found")
|
|
return SwarmHostView(**row)
|