'Critic-Prompt', 'generate' => 'Generierungs-Prompt', 'revise' => 'Revisions-Prompt', 'system' => 'System-Prompt', 'other' => 'Sonstiges', ]; public function __construct(?ManagePromptsUseCase $promptsUseCase = null) { $this->promptsUseCase = $promptsUseCase ?? new ManagePromptsUseCase(); } public function index(): void { $this->view('prompts.index', [ 'title' => 'Prompts verwalten', 'prompts' => array_map(fn ($dto) => $dto->toArray(), $this->promptsUseCase->getAll()), 'stats' => $this->promptsUseCase->getStatistics(), 'promptTypes' => self::PROMPT_TYPES, ]); } public function promptsNew(): void { $this->view('prompts.form', [ 'title' => 'Neuer Prompt', 'prompt' => null, 'promptTypes' => self::PROMPT_TYPES, 'isEdit' => false, ]); } public function store(): void { $this->requireCsrf(); $command = CreatePromptCommand::fromRequest($_POST); $errors = $command->validate(); if ($errors !== []) { $_SESSION['error'] = implode(' ', $errors); header('Location: /prompts/new'); exit; } $result = $this->promptsUseCase->create( name: $command->name, version: $command->version, content: $command->content, isActive: $command->isActive ); if (!$result->success) { $_SESSION['error'] = $result->message; header('Location: /prompts/new'); exit; } $_SESSION['success'] = $result->message; header('Location: /prompts/' . $result->id); exit; } public function show(string $id): void { $prompt = $this->promptsUseCase->getById((int) $id); if ($prompt === null) { $this->notFound('Prompt nicht gefunden'); } $this->view('prompts.show', [ 'title' => $prompt->name, 'prompt' => $prompt->toArray(), 'linkedCritics' => $this->promptsUseCase->getLinkedCritics((int) $id), 'promptTypes' => self::PROMPT_TYPES, ]); } public function edit(string $id): void { $prompt = $this->promptsUseCase->getById((int) $id); if ($prompt === null) { $this->notFound('Prompt nicht gefunden'); } $this->view('prompts.form', [ 'title' => 'Bearbeiten: ' . $prompt->name, 'prompt' => $prompt->toArray(), 'promptTypes' => self::PROMPT_TYPES, 'isEdit' => true, ]); } public function update(string $id): void { $this->requireCsrf(); $command = UpdatePromptCommand::fromRequest((int) $id, $_POST); $errors = $command->validate(); if ($errors !== []) { $_SESSION['error'] = implode(' ', $errors); header('Location: /prompts/' . $id . '/edit'); exit; } $result = $this->promptsUseCase->update( id: $command->id, name: $command->name, version: $command->version, content: $command->content, isActive: $command->isActive ); if (!$result->success) { $_SESSION['error'] = $result->message; header('Location: /prompts/' . $id . '/edit'); exit; } $_SESSION['success'] = $result->message; header('Location: /prompts/' . $id); exit; } public function delete(string $id): void { $this->requireCsrf(); $result = $this->promptsUseCase->delete((int) $id); if (!$result->success) { $_SESSION['error'] = $result->message; header('Location: /prompts/' . $id); exit; } $_SESSION['success'] = $result->message; header('Location: /prompts'); exit; } public function duplicate(string $id): void { $this->requireCsrf(); $result = $this->promptsUseCase->duplicate((int) $id); if (!$result->success) { $_SESSION['error'] = $result->message; header('Location: /prompts/' . $id); exit; } $_SESSION['success'] = $result->message; header('Location: /prompts/' . $result->id . '/edit'); exit; } }