ContentController.php
- Pfad:
src/Controller/Api/ContentController.php - Namespace: Controller\Api
- Zeilen: 89 | Größe: 2,604 Bytes
- Geändert: 2025-12-28 23:30:48 | 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 Domain\Repository\ContentRepositoryInterface
- use Domain\Repository\ContentRepositoryInterface
- use Framework\Controller
Klassen 1
-
ContentControllerclass Zeile 12
Funktionen 3
-
__construct()public Zeile 16 -
update()public Zeile 21 -
sendError()private Zeile 79
Versionen 6
-
v6
2025-12-28 23:30 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation -
v5
2025-12-27 11:43 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation -
v4
2025-12-25 12:52 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation -
v3
2025-12-23 07:53 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation -
v2
2025-12-23 04:43 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation -
v1
2025-12-23 04:25 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation
Code
<?php
declare(strict_types=1);
namespace Controller\Api;
// @responsibility: REST-API für Content-Aufträge
use Domain\Repository\ContentRepositoryInterface;
use Framework\Controller;
class ContentController extends Controller
{
private ContentRepositoryInterface $repository;
public function __construct(ContentRepositoryInterface $repository)
{
$this->repository = $repository;
}
public function update(int $id): void
{
$this->requireCsrf();
try {
$order = $this->repository->findOrder($id);
if ($order === null) {
$this->sendError('Auftrag nicht gefunden', 404);
return;
}
// Accept both JSON and form data
$input = $this->getJsonInput();
if (empty($input)) {
$input = $_POST;
}
if (!isset($input['title']) || trim((string) $input['title']) === '') {
$this->sendError('Titel ist erforderlich', 400);
return;
}
if (!isset($input['briefing']) || trim((string) $input['briefing']) === '') {
$this->sendError('Briefing ist erforderlich', 400);
return;
}
$this->repository->updateOrder($id, [
'title' => $input['title'],
'briefing' => $input['briefing'],
'author_profile_id' => !empty($input['author_profile_id']) ? (int) $input['author_profile_id'] : null,
'contract_id' => !empty($input['contract_id']) ? (int) $input['contract_id'] : null,
'structure_id' => !empty($input['structure_id']) ? (int) $input['structure_id'] : null,
]);
// HTMX: Redirect to detail page
if ($this->isHtmxRequest()) {
$this->htmxRedirect('/content/' . $id);
return;
}
// JSON fallback
$updatedOrder = $this->repository->findOrder($id);
$this->json([
'success' => true,
'data' => $updatedOrder,
]);
} catch (\Exception $e) {
error_log(sprintf('[API.Content.update] %s: %s', get_class($e), $e->getMessage()));
$this->sendError($e->getMessage());
}
}
private function sendError(string $message, int $status = 500): void
{
if ($this->isHtmxRequest()) {
$this->htmxError($message);
return;
}
$this->json(['success' => false, 'error' => $message], $status);
}
}