Files
lagomareGateKeeperBot/src/repository/gates_repository.py
2025-08-22 01:34:25 +02:00

21 lines
795 B
Python

import json
from models import Status, Gate
class GatesRepository:
def __init__(self, json_path: str = "./data/gates.json"):
self._json_path: str = json_path
self._gates: dict[str, Gate] = self._load_gates()
def _load_gates(self) -> dict[str, Gate]:
try:
with open(self._json_path, "r") as file:
gates_data = json.load(file)
return {gate: Gate.from_dict(data) for gate, data in gates_data.items()}
except Exception:
return {}
def get_by_key(self, key: str) -> Gate | None:
return self._gates[key] if key in self._gates else None
def get_all_enabled(self) -> list[Gate]:
return [value for key, value in self._gates.items() if self._gates[key].status == Status.ENABLED]