17 lines
473 B
Python
17 lines
473 B
Python
from __future__ import annotations
|
|
|
|
import json
|
|
from http import HTTPStatus
|
|
|
|
|
|
class AlertHttpMixin:
|
|
def save_alert(self) -> None:
|
|
try:
|
|
body = self.read_json_body()
|
|
self.send_json(
|
|
{"ok": True, **self.application_service.create_alert(body)},
|
|
HTTPStatus.CREATED,
|
|
)
|
|
except (ValueError, json.JSONDecodeError) as exc:
|
|
self.send_json({"error": str(exc)}, HTTPStatus.BAD_REQUEST)
|