feat(templates): add OpenAPI-first CRUD app scaffold with mock data
- 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
This commit is contained in:
41
openapi_first/templates/crud_app/data.py
Normal file
41
openapi_first/templates/crud_app/data.py
Normal file
@@ -0,0 +1,41 @@
|
||||
"""
|
||||
In-memory mock data store for CRUD example.
|
||||
|
||||
This module intentionally avoids persistence and concurrency guarantees.
|
||||
It is suitable for demos, tests, and scaffolding only.
|
||||
"""
|
||||
|
||||
from typing import Dict
|
||||
|
||||
_items: Dict[int, dict] = {
|
||||
1: {"id": 1, "name": "Apple", "price": 0.5},
|
||||
2: {"id": 2, "name": "Banana", "price": 0.3},
|
||||
}
|
||||
|
||||
_next_id = 3
|
||||
|
||||
|
||||
def list_items():
|
||||
return list(_items.values())
|
||||
|
||||
|
||||
def get_item(item_id: int):
|
||||
return _items[item_id]
|
||||
|
||||
|
||||
def create_item(payload: dict):
|
||||
global _next_id
|
||||
item = {"id": _next_id, **payload}
|
||||
_items[_next_id] = item
|
||||
_next_id += 1
|
||||
return item
|
||||
|
||||
|
||||
def update_item(item_id: int, payload: dict):
|
||||
item = {"id": item_id, **payload}
|
||||
_items[item_id] = item
|
||||
return item
|
||||
|
||||
|
||||
def delete_item(item_id: int):
|
||||
del _items[item_id]
|
||||
Reference in New Issue
Block a user