refactor: establish standalone application boundary

This commit is contained in:
leefer
2026-08-03 21:42:25 +08:00
parent cc5fb8d73e
commit e1e76cd51e
324 changed files with 63090 additions and 44743 deletions
+47
View File
@@ -0,0 +1,47 @@
from __future__ import annotations
import re
from datetime import date
from http import HTTPStatus
from urllib.parse import parse_qs
class AlertRoutesMixin:
def _handle_alerts_get(self, parsed) -> bool:
if parsed.path == "/api/alerts":
query = parse_qs(parsed.query)
try:
self.send_json(
self.application_service.alert_center(
query.get("status", ["all"])[0],
query.get("as_of", [date.today().isoformat()])[0],
)
)
except ValueError as exc:
self.send_json({"error": str(exc)}, HTTPStatus.BAD_REQUEST)
return True
return False
def _handle_alerts_post(self, parsed) -> bool:
alert_read_match = re.fullmatch(r"/api/alerts/(\d+)/read", parsed.path)
if alert_read_match:
self.send_json(
{"ok": True, **self.application_service.mark_alert_read(int(alert_read_match.group(1)))}
)
return True
if parsed.path == "/api/alerts/read-all":
body = self.read_json_body(True)
self.send_json(
{"ok": True, **self.application_service.mark_all_alerts_read(str(body.get("as_of") or ""))}
)
return True
return False
def _handle_alerts_delete(self, parsed) -> bool:
alert_match = re.fullmatch(r"/api/alerts/(\d+)", parsed.path)
if alert_match:
self.send_json(
{"ok": True, **self.application_service.delete_alert(int(alert_match.group(1)))}
)
return True
return False