ConfigController.php
- Pfad:
src/Controller/Api/ConfigController.php - Namespace: Controller\Api
- Zeilen: 87 | Größe: 2,178 Bytes
- Geändert: 2025-12-27 10:26:40 | Gescannt: 2025-12-31 10:22:15
Code Hygiene Score: 100
- Dependencies: 100 (25%)
- LOC: 100 (20%)
- Methods: 100 (20%)
- Secrets: 100 (15%)
- Classes: 100 (10%)
- Magic Numbers: 100 (10%)
Keine Issues gefunden.
Dependencies 4
- extends Framework\Controller
- constructor UseCases\Config\ManageConfigUseCase
- use Framework\Controller
- use UseCases\Config\ManageConfigUseCase
Klassen 1
-
ConfigControllerclass Zeile 12
Funktionen 3
-
__construct()public Zeile 14 -
show()public Zeile 22 -
update()public Zeile 44
Code
<?php
declare(strict_types=1);
namespace Controller\Api;
// @responsibility: JSON-API für Config-Operationen (Chat-Integration)
use Framework\Controller;
use UseCases\Config\ManageConfigUseCase;
class ConfigController extends Controller
{
public function __construct(
private ManageConfigUseCase $configUseCase
) {
}
/**
* GET /api/v1/config/{id}
*/
public function show(string $id): void
{
$config = $this->configUseCase->getById((int) $id);
if ($config === null) {
$this->json(['error' => 'Config nicht gefunden'], 404);
return;
}
$this->json([
'id' => $config->id,
'name' => $config->name,
'type' => $config->type,
'content' => $config->content,
'version' => $config->version,
]);
}
/**
* POST /api/v1/config/{id}
*/
public function update(string $id): void
{
$this->requireCsrf();
$config = $this->configUseCase->getById((int) $id);
if ($config === null) {
$this->json(['error' => 'Config nicht gefunden'], 404);
return;
}
$newContent = $_POST['content'] ?? '';
// Auto-increment Version
$currentVersion = $config->version ?? '1.0';
$versionParts = explode('.', $currentVersion);
$newVersion = $versionParts[0] . '.' . ((int) ($versionParts[1] ?? 0) + 1);
$result = $this->configUseCase->update(
id: (int) $id,
name: $config->name,
slug: $config->slug ?? '',
description: $config->description,
content: $newContent,
newVersion: $newVersion,
changeDescription: 'Chat UI Update',
status: $config->status ?? 'active',
parentId: $config->parentId
);
if (!$result->success) {
$this->json(['error' => $result->message], 400);
return;
}
$this->json([
'success' => true,
'version' => $newVersion,
'message' => "Version {$newVersion} gespeichert",
]);
}
}