@@ -70,6 +70,8 @@ class Router
|
||||
$path === '/alerts/search' && $method === 'GET' => $this->searchAlerts(),
|
||||
preg_match('#^/alerts/(\d+)/ack$#', $path, $m) && $method === 'POST'
|
||||
=> $this->ackAlert((int) $m[1]),
|
||||
preg_match('#^/alerts/(\d+)/status$#', $path, $m) && $method === 'POST'
|
||||
=> $this->updateAlertStatus((int) $m[1]),
|
||||
preg_match('#^/alerts/counts$#', $path) && $method === 'GET'
|
||||
=> $this->repo->getAlertCounts(),
|
||||
|
||||
@@ -198,6 +200,18 @@ class Router
|
||||
return ['status' => 'acknowledged', 'id' => $id];
|
||||
}
|
||||
|
||||
private function updateAlertStatus(int $id): array
|
||||
{
|
||||
$body = json_decode(file_get_contents('php://input'), true);
|
||||
$status = AlertStatus::tryFrom($body['status'] ?? '');
|
||||
if (!$status) {
|
||||
http_response_code(400);
|
||||
return ['error' => 'Invalid status. Use: open, acknowledged, resolved'];
|
||||
}
|
||||
$this->repo->updateAlertStatus($id, $status);
|
||||
return ['status' => $status->value, 'id' => $id];
|
||||
}
|
||||
|
||||
private function searchAlerts(): array
|
||||
{
|
||||
$query = $_GET['q'] ?? '';
|
||||
|
||||
Reference in New Issue
Block a user