store.py 745 B

12345678910111213141516171819202122232425262728
  1. from __future__ import annotations
  2. from bom_assistant.scouting.errors import SessionNotFoundError
  3. from bom_assistant.session.models import BomSession
  4. class SessionStore:
  5. def __init__(self) -> None:
  6. self._sessions: dict[str, BomSession] = {}
  7. def create(self, session: BomSession) -> None:
  8. self._sessions[session.session_id] = session
  9. def get(self, session_id: str) -> BomSession:
  10. session = self._sessions.get(session_id)
  11. if session is None:
  12. raise SessionNotFoundError(session_id)
  13. return session
  14. def save(self, session: BomSession) -> None:
  15. self._sessions[session.session_id] = session
  16. _store = SessionStore()
  17. def get_store() -> SessionStore:
  18. return _store