Backup #2067

ID2067
Dateipfad/var/www/dev.campus.systemische-tools.de/src/Controller/Api/ContentController.php
Version6
Typ modified
Größe2.4 KB
Hash51119cc519425b9e979d29030009a2a2d07fe5e9002588a499f15e6898de2e4a
Datum2025-12-28 23:30:48
Geändert vonclaude-code-hook
GrundClaude Code Pre-Hook Backup vor Edit-Operation
Datei existiert Ja

Dateiinhalt

<?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) {
            $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);
    }
}

Vollständig herunterladen

Aktionen

Herunterladen

Andere Versionen dieser Datei

ID Version Typ Größe Datum
2067 6 modified 2.4 KB 2025-12-28 23:30
1672 5 modified 1.8 KB 2025-12-27 11:43
1274 4 modified 1.8 KB 2025-12-25 12:52
701 3 modified 1.7 KB 2025-12-23 07:53
623 2 modified 1.7 KB 2025-12-23 04:43
592 1 modified 1.7 KB 2025-12-23 04:25

← Zurück zur Übersicht