- include CRUD OpenAPI spec - add in-memory mock data store - implement OpenAPI-bound route handlers - provide runnable FastAPI bootstrap - include end-to-end integration test
51 lines
1.1 KiB
Python
51 lines
1.1 KiB
Python
"""
|
|
CRUD route handlers bound via OpenAPI operationId.
|
|
|
|
These handlers explicitly control HTTP status codes to ensure
|
|
runtime behavior matches the OpenAPI contract.
|
|
"""
|
|
|
|
from fastapi import Response, HTTPException
|
|
|
|
from data import (
|
|
list_items as _list_items,
|
|
get_item as _get_item,
|
|
create_item as _create_item,
|
|
update_item as _update_item,
|
|
delete_item as _delete_item,
|
|
)
|
|
|
|
|
|
def list_items():
|
|
return _list_items()
|
|
|
|
|
|
def get_item(item_id: int):
|
|
try:
|
|
return _get_item(item_id)
|
|
except KeyError:
|
|
raise HTTPException(status_code=404, detail="Item not found")
|
|
|
|
|
|
def create_item(payload: dict, response: Response):
|
|
item = _create_item(payload)
|
|
response.status_code = 201
|
|
return item
|
|
|
|
|
|
def update_item(item_id: int, payload: dict):
|
|
try:
|
|
return _update_item(item_id, payload)
|
|
except KeyError:
|
|
raise HTTPException(status_code=404, detail="Item not found")
|
|
|
|
|
|
def delete_item(item_id: int, response: Response):
|
|
try:
|
|
_delete_item(item_id)
|
|
except KeyError:
|
|
raise HTTPException(status_code=404, detail="Item not found")
|
|
|
|
response.status_code = 204
|
|
return None
|