@@ -94,6 +94,13 @@ class Router
|
||||
$path === '/config/telegram' && $method === 'PUT'
|
||||
=> $this->updateTelegramConfig(),
|
||||
|
||||
$path === '/false-positives' && $method === 'GET'
|
||||
=> $this->repo->getFalsePositives(),
|
||||
$path === '/false-positives' && $method === 'POST'
|
||||
=> $this->createFalsePositive(),
|
||||
preg_match('#^/false-positives/(\d+)$#', $path, $m) && $method === 'DELETE'
|
||||
=> $this->deleteFalsePositive((int) $m[1]),
|
||||
|
||||
default => throw new \RuntimeException('Not found', 404),
|
||||
};
|
||||
|
||||
@@ -315,4 +322,24 @@ class Router
|
||||
$this->repo->setConfig('telegram_chat_id', $body['chat_id'] ?? '');
|
||||
return $this->getTelegramConfig();
|
||||
}
|
||||
|
||||
private function createFalsePositive(): array
|
||||
{
|
||||
$body = json_decode(file_get_contents('php://input'), true);
|
||||
$pattern = $body['pattern'] ?? '';
|
||||
$description = $body['description'] ?? '';
|
||||
|
||||
if (empty($pattern)) {
|
||||
http_response_code(400);
|
||||
return ['error' => 'Missing "pattern" field'];
|
||||
}
|
||||
|
||||
return $this->repo->createFalsePositive($pattern, $description);
|
||||
}
|
||||
|
||||
private function deleteFalsePositive(int $id): array
|
||||
{
|
||||
$this->repo->deleteFalsePositive($id);
|
||||
return ['status' => 'deleted', 'id' => $id];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user