24 lines
649 B
Python
24 lines
649 B
Python
import uuid
|
|
from datetime import datetime
|
|
from typing import Dict, List, Optional
|
|
|
|
|
|
class ExampleService:
|
|
def __init__(self):
|
|
self._store: Dict[str, dict] = {}
|
|
|
|
async def list_all(self) -> List[dict]:
|
|
return list(self._store.values())
|
|
|
|
async def get_by_id(self, example_id: str) -> Optional[dict]:
|
|
return self._store.get(example_id)
|
|
|
|
async def create(self, data: dict) -> dict:
|
|
example_id = str(uuid.uuid4())
|
|
item = {
|
|
"id": example_id,
|
|
"created_at": datetime.utcnow().isoformat(),
|
|
**data,
|
|
}
|
|
self._store[example_id] = item
|
|
return item |