125 lines
3.4 KiB
Python
125 lines
3.4 KiB
Python
"""Persistence contracts used by services during the S4 repository migration."""
|
|
from __future__ import annotations
|
|
|
|
from datetime import datetime
|
|
from typing import Protocol
|
|
|
|
from ..models import Group, Message, Organization, Persona, TrainingSession, User
|
|
|
|
|
|
class OrganizationRepository(Protocol):
|
|
"""Tenant organization persistence contract."""
|
|
|
|
def get(self, organization_id: str) -> Organization | None: ...
|
|
|
|
def list(self, *, active_only: bool = False) -> list[Organization]: ...
|
|
|
|
def create(
|
|
self,
|
|
*,
|
|
organization_id: str,
|
|
name: str,
|
|
plan: str = "trial",
|
|
seats: int = 5,
|
|
active: bool = True,
|
|
) -> Organization: ...
|
|
|
|
def update(self, organization_id: str, **fields: object) -> Organization: ...
|
|
|
|
|
|
class UserRepository(Protocol):
|
|
"""Tenant-scoped user persistence contract."""
|
|
|
|
def get(self, user_id: str, *, org_id: str) -> User | None: ...
|
|
|
|
def get_by_username(self, username: str, *, org_id: str) -> User | None: ...
|
|
|
|
def get_by_email(self, email: str | None, *, org_id: str) -> User | None: ...
|
|
|
|
def list_for_org(self, org_id: str, *, include_inactive: bool = True) -> list[User]: ...
|
|
|
|
def create(
|
|
self,
|
|
*,
|
|
user_id: str,
|
|
org_id: str,
|
|
username: str,
|
|
password_hash: str,
|
|
name: str,
|
|
role: str,
|
|
email: str | None = None,
|
|
active: bool = True,
|
|
must_setup: bool = False,
|
|
accepted_terms: bool = False,
|
|
accepted_terms_at: datetime | None = None,
|
|
auth_version: int = 0,
|
|
) -> User: ...
|
|
|
|
def update(self, user_id: str, *, org_id: str, **fields: object) -> User: ...
|
|
|
|
|
|
class GroupRepository(Protocol):
|
|
"""Tenant-scoped group/persona aggregate contract."""
|
|
|
|
def get(self, group_id: str, *, org_id: str | None = None) -> Group | None: ...
|
|
|
|
def list_for_org(self, org_id: str) -> list[Group]: ...
|
|
|
|
def create(self, *, group_id: str, org_id: str, name: str, **fields: object) -> Group: ...
|
|
|
|
def update(self, group_id: str, *, org_id: str, **fields: object) -> Group: ...
|
|
|
|
def get_persona(
|
|
self,
|
|
group_id: str,
|
|
persona_id: str,
|
|
*,
|
|
org_id: str | None = None,
|
|
) -> Persona | None: ...
|
|
|
|
def list_personas(self, group_id: str, *, org_id: str | None = None) -> list[Persona]: ...
|
|
|
|
def create_persona(
|
|
self,
|
|
*,
|
|
persona_id: str,
|
|
group_id: str,
|
|
tier: str,
|
|
public_json: dict[str, object],
|
|
**fields: object,
|
|
) -> Persona: ...
|
|
|
|
|
|
class SessionRepository(Protocol):
|
|
"""Tenant-scoped training-session and message aggregate contract."""
|
|
|
|
def get(self, session_id: str, *, org_id: str) -> TrainingSession | None: ...
|
|
|
|
def list_for_user(self, org_id: str, user_id: str) -> list[TrainingSession]: ...
|
|
|
|
def create(
|
|
self,
|
|
*,
|
|
session_id: str,
|
|
org_id: str,
|
|
user_id: str,
|
|
group_id: str,
|
|
persona_id: str,
|
|
**fields: object,
|
|
) -> TrainingSession: ...
|
|
|
|
def update(self, session_id: str, *, org_id: str, **fields: object) -> TrainingSession: ...
|
|
|
|
def list_messages(self, session_id: str, *, org_id: str) -> list[Message]: ...
|
|
|
|
def append_message(
|
|
self,
|
|
*,
|
|
session_id: str,
|
|
org_id: str,
|
|
message_id: str,
|
|
sequence: int,
|
|
role: str,
|
|
text: str,
|
|
) -> Message: ...
|