44 lines
1.2 KiB
Python
44 lines
1.2 KiB
Python
from core.models.session.SessionState import SessionState
|
|
from core.controllers.ProfileController import ProfileController
|
|
from core.infrastructure.global_state import ProfileStateRepository
|
|
|
|
|
|
class SessionStateController:
|
|
@staticmethod
|
|
def get(id: int):
|
|
return SessionState.find_by_id(id)
|
|
|
|
@staticmethod
|
|
def get_or_new(id: int):
|
|
session_state = SessionStateController.get(id)
|
|
|
|
if session_state is None:
|
|
# Update the Singleton Repo
|
|
repo = ProfileStateRepository()
|
|
repo.sync_session_added(id)
|
|
|
|
# Create and save the session
|
|
session_state = SessionState(id)
|
|
session_state.save()
|
|
return session_state
|
|
|
|
return session_state
|
|
|
|
@staticmethod
|
|
def exists(id: int):
|
|
return SessionState.exists(id)
|
|
|
|
@staticmethod
|
|
def all():
|
|
return SessionState.all()
|
|
|
|
@staticmethod
|
|
def update_or_create(session_state):
|
|
session_state.save()
|
|
# Ensure repo knows this session exists
|
|
ProfileStateRepository().sync_session_added(session_state.id)
|
|
|
|
@staticmethod
|
|
def remove(profile_id: int):
|
|
SessionState.dissolve(profile_id)
|
|
ProfileStateRepository().sync_session_removed(profile_id)
|