@@ -65,6 +65,8 @@ class Router
|
||||
$path === '/rules' && $method === 'POST' => $this->createRule(),
|
||||
preg_match('#^/rules/(\d+)$#', $path, $m) && $method === 'DELETE'
|
||||
=> $this->deleteEntity('rule', (int) $m[1]),
|
||||
preg_match('#^/rules/(\d+)$#', $path, $m) && $method === 'PUT'
|
||||
=> $this->updateRule((int) $m[1]),
|
||||
|
||||
$path === '/alerts' && $method === 'GET' => $this->getAlerts(),
|
||||
$path === '/alerts/search' && $method === 'GET' => $this->searchAlerts(),
|
||||
@@ -185,6 +187,19 @@ class Router
|
||||
return ['status' => 'deleted', 'id' => $id];
|
||||
}
|
||||
|
||||
private function updateRule(int $id): mixed
|
||||
{
|
||||
$body = json_decode(file_get_contents('php://input'), true);
|
||||
return $this->repo->updateRule(
|
||||
id: $id,
|
||||
name: $body['name'],
|
||||
pattern: $body['pattern'],
|
||||
severity: $body['severity'] ?? 'warning',
|
||||
rateLimitSeconds: $body['rate_limit_seconds'] ?? null,
|
||||
active: $body['active'] ?? true,
|
||||
);
|
||||
}
|
||||
|
||||
private function getAlerts(): mixed
|
||||
{
|
||||
$limit = (int) ($_GET['limit'] ?? 100);
|
||||
|
||||
Reference in New Issue
Block a user