Initial FastAPI + SQLite + Alembic
This commit is contained in:
25
fastapi_demo/app/repositories/memory_assets_repo.py
Normal file
25
fastapi_demo/app/repositories/memory_assets_repo.py
Normal file
@@ -0,0 +1,25 @@
|
||||
from uuid import UUID
|
||||
from fastapi_demo.app.repositories.assets_repo import AssetsRepo
|
||||
from fastapi_demo.app.schemas.asset import AssetOut, AssetEventOut
|
||||
|
||||
|
||||
class MemoryAssetsRepo(AssetsRepo):
|
||||
def __init__(self) -> None:
|
||||
self.assets: dict[UUID, AssetOut] = {}
|
||||
self.events: dict[UUID, list[AssetEventOut]] = {}
|
||||
|
||||
def create(self, asset: AssetOut) -> None:
|
||||
self.assets[asset.id] = asset
|
||||
self.events.setdefault(asset.id, [])
|
||||
|
||||
def get(self, asset_id: UUID) -> AssetOut | None:
|
||||
return self.assets.get(asset_id)
|
||||
|
||||
def update(self, asset: AssetOut) -> None:
|
||||
self.assets[asset.id] = asset
|
||||
|
||||
def add_event(self, event: AssetEventOut) -> None:
|
||||
self.events.setdefault(event.asset_id, []).append(event)
|
||||
|
||||
def list_events(self, asset_id: UUID) -> list[AssetEventOut]:
|
||||
return list(self.events.get(asset_id, []))
|
||||
Reference in New Issue
Block a user