sp-hydra-veil-core/core/controllers/SessionStateController.py

80 lines
2.1 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)
# 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 global state:
# global_state = GlobalState()
# if id not in global_state.session_profile_ids: # sanity check.
# global_state.session_profile_ids.append(id)
# # create new:
# return SessionState(id)
# 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()