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); } }