Files
docs/standards/mcp/templates/app/interfaces/treatments/routes.py
Vishesh 'ironeagle' Bangotra 0cb35d10a6 Phase 7: serve the vet sample from the template tools and docs
- build.py: _TEMPLATE_COMPONENTS rewritten around the vet sample (53 kinds —
  per-resource slices, jobs, worked appointment_reminder family, tests);
  seed tokens dropped from the manifest ('sample: vet' instead)
- registry.py: get_app_component(kind) no longer renames item/example seeds;
  prompts and tool docs updated to 'copy a slice and adapt'
- templates/README.md, 01_build_recipe, 40_ui_admin, wiki/03 updated off the
  old seed scheme; repo inventory/config now exclude vet (docs move under
  standards; react/vet itself is deleted in a later phase)
- regenerated MCP bundle, vendored templates, and site output
2026-10-20 14:58:17 +05:30

93 lines
2.5 KiB
Python

"""# Summary
Treatments route handlers — names must match openapi.yaml operationIds.
Notes:
``list_treatments`` returns a plain array (the catalogue is small and
unpaginated by contract).
"""
from fastapi import Request, Response
from interfaces._common import delete_or_404, dump, read_or_404, svc
async def list_treatments(request: Request) -> list[dict]:
"""List treatments (catalogue, unpaginated).
Args:
request (Request): Incoming request.
Returns:
list[dict]: All treatment documents.
"""
docs = await svc(request, "treatment").search({})
return [dump(d) for d in docs]
async def create_treatment(request: Request, body: dict, response: Response) -> dict:
"""Add a treatment (admin only).
Args:
request (Request): Incoming request.
body (dict): Treatment fields (``id`` ignored).
response (Response): Response object; set to 201 on success.
Returns:
dict: The created treatment.
"""
response.status_code = 201
body.pop("id", None)
doc = await svc(request, "treatment").create(body)
return dump(doc)
async def get_treatment(request: Request, id: int) -> dict:
"""Fetch one treatment by id.
Args:
request (Request): Incoming request.
id (int): Treatment identifier.
Returns:
dict: The treatment document.
Raises:
HTTPException: 404 when the treatment does not exist.
"""
return dump(await read_or_404(svc(request, "treatment"), id, "treatment"))
async def update_treatment(request: Request, id: int, body: dict) -> dict:
"""Replace a treatment by id.
Args:
request (Request): Incoming request.
id (int): Treatment identifier.
body (dict): Full replacement payload.
Returns:
dict: The updated treatment.
Raises:
HTTPException: 404 when the treatment does not exist.
"""
await read_or_404(svc(request, "treatment"), id, "treatment")
body.pop("id", None)
doc = await svc(request, "treatment").update(id, body)
return dump(doc)
async def delete_treatment(request: Request, id: int, response: Response) -> None:
"""Delete a treatment by id.
Args:
request (Request): Incoming request.
id (int): Treatment identifier.
response (Response): Response object; set to 204 on success.
Raises:
HTTPException: 404 when the treatment does not exist.
"""
await delete_or_404(svc(request, "treatment"), id, "treatment")
response.status_code = 204