- 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
42 lines
801 B
Python
42 lines
801 B
Python
"""
|
|
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]
|