making sources editable, adding sorting in runles
Deploy / deploy (push) Successful in 8s

This commit is contained in:
2026-05-06 19:14:06 +02:00
parent 5b5fd78eb6
commit fae485c9cb
3 changed files with 140 additions and 60 deletions
+16
View File
@@ -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);
+9
View File
@@ -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