feat(backend): refactor mono repository

This commit is contained in:
2025-08-27 11:04:56 -04:00
parent d0dbba21fb
commit be1c729220
37 changed files with 2534 additions and 452 deletions

42
backend/models/enums.py Normal file
View File

@@ -0,0 +1,42 @@
# ------------------------------------------------------------
# Centralised enumeration definitions for the datamodel layer.
# Keeping them in one module avoids circular imports and makes
# typechecking / IDE completion straightforward.
# ------------------------------------------------------------
from __future__ import annotations
from enum import StrEnum
from typing import Any, Iterable
class ScheduleStatus(StrEnum):
"""
Canonical status values for a ``Schedule`` row.
Using ``StrEnum`` means the enum members behave like regular strings
(e.g. they can be written directly to SQLite) while still giving us
the safety and autocomplete of an enum.
"""
PENDING = "pending"
ACCEPTED = "accepted"
DECLINED = "declined"
@classmethod
def from_raw(cls, value: Any) -> "ScheduleStatus":
"""
Convert an arbitrary value (often a plain string coming from the DB)
into a ``ScheduleStatus`` member.
Raises
------
ValueError
If the value does not correspond to any defined member.
"""
if isinstance(value, cls):
return value
try:
# ``cls(value)`` works because ``StrEnum`` subclasses ``str``.
return cls(value)
except ValueError as exc:
raise ValueError(f"Invalid ScheduleStatus: {value!r}") from exc