This commit is contained in:
@@ -63,6 +63,8 @@ class Router
|
||||
$path === '/sources' && $method === 'POST' => $this->createSource(),
|
||||
preg_match('#^/sources/(\d+)$#', $path, $m) && $method === 'DELETE'
|
||||
=> $this->deleteEntity('source', (int) $m[1]),
|
||||
preg_match('#^/sources/(\d+)$#', $path, $m) && $method === 'PUT'
|
||||
=> $this->updateSource((int) $m[1]),
|
||||
|
||||
$path === '/rules' && $method === 'GET' => $this->repo->getRules(),
|
||||
$path === '/rules' && $method === 'POST' => $this->createRule(),
|
||||
@@ -195,6 +197,20 @@ class Router
|
||||
return ['status' => 'deleted', 'id' => $id];
|
||||
}
|
||||
|
||||
private function updateSource(int $id): mixed
|
||||
{
|
||||
$body = json_decode(file_get_contents('php://input'), true);
|
||||
$type = LogSourceType::from($body['type'] ?? '');
|
||||
return $this->repo->updateSource(
|
||||
id: $id,
|
||||
name: $body['name'],
|
||||
type: $type,
|
||||
address: $body['address'],
|
||||
labels: $body['labels'] ?? [],
|
||||
active: $body['active'] ?? true,
|
||||
);
|
||||
}
|
||||
|
||||
private function updateRule(int $id): mixed
|
||||
{
|
||||
$body = json_decode(file_get_contents('php://input'), true);
|
||||
|
||||
@@ -46,6 +46,15 @@ class Repository
|
||||
$this->db->pdo()->prepare("DELETE FROM log_sources WHERE id = ?")->execute([$id]);
|
||||
}
|
||||
|
||||
public function updateSource(int $id, string $name, LogSourceType $type, string $address, array $labels = [], bool $active = true): LogSource
|
||||
{
|
||||
$stmt = $this->db->pdo()->prepare(
|
||||
"UPDATE log_sources SET name = ?, type = ?, address = ?, labels = ?, active = ? WHERE id = ?"
|
||||
);
|
||||
$stmt->execute([$name, $type->value, $address, json_encode($labels), (int) $active, $id]);
|
||||
return $this->getSource($id);
|
||||
}
|
||||
|
||||
// --- Rules ---
|
||||
|
||||
public function getRules(): array
|
||||
|
||||
Reference in New Issue
Block a user