Backup #1752
| ID | 1752 |
| Dateipfad | /var/www/dev.campus.systemische-tools.de/src/Controller/PromptsController.php |
| Version | 17 |
| Typ |
modified |
| Größe | 5.3 KB |
| Hash | d65059a2ca158b97a414cd3c1e56c49557be2a9a1cd6d817f87c6d630bd29dd6 |
| Datum | 2025-12-27 12:46:19 |
| Geändert von | claude-code-hook |
| Grund | Claude Code Pre-Hook Backup vor Edit-Operation |
| Datei existiert |
Ja
|
Dateiinhalt
<?php
declare(strict_types=1);
namespace Controller;
// @responsibility: HTTP-Endpunkte für Prompt-Verwaltung (CRUD, Duplizieren)
use Framework\Controller;
use UseCases\Command\CreatePromptCommand;
use UseCases\Command\UpdatePromptCommand;
use UseCases\Prompts\ManagePromptsUseCase;
class PromptsController extends Controller
{
private ManagePromptsUseCase $promptsUseCase;
private const PROMPT_TYPES = [
'critic' => 'Critic-Prompt',
'generate' => 'Generierungs-Prompt',
'revise' => 'Revisions-Prompt',
'system' => 'System-Prompt',
'other' => 'Sonstiges',
];
public function __construct(ManagePromptsUseCase $promptsUseCase)
{
$this->promptsUseCase = $promptsUseCase;
}
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();
$isHtmx = $this->isHtmxRequest();
$command = CreatePromptCommand::fromRequest($_POST);
$errors = $command->validate();
if ($errors !== []) {
if ($isHtmx) {
$this->htmxError(implode(' ', $errors));
return;
}
$_SESSION['error'] = implode(' ', $errors);
$this->redirect('/prompts/new');
}
$result = $this->promptsUseCase->create(
name: $command->name,
version: $command->version,
content: $command->content,
isActive: $command->isActive
);
if (!$result->success) {
if ($isHtmx) {
$this->htmxError($result->message);
return;
}
$_SESSION['error'] = $result->message;
$this->redirect('/prompts/new');
}
if ($isHtmx) {
$this->htmxRedirect('/prompts/' . $result->id);
return;
}
$_SESSION['success'] = $result->message;
$this->redirect('/prompts/' . $result->id);
}
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);
$this->redirect('/prompts/' . $id . '/edit');
}
$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;
$this->redirect('/prompts/' . $id . '/edit');
}
$_SESSION['success'] = $result->message;
$this->redirect('/prompts/' . $id);
}
public function delete(string $id): void
{
$this->requireCsrf();
$result = $this->promptsUseCase->delete((int) $id);
if (!$result->success) {
$_SESSION['error'] = $result->message;
$this->redirect('/prompts/' . $id);
}
$_SESSION['success'] = $result->message;
$this->redirect('/prompts');
}
public function duplicate(string $id): void
{
$this->requireCsrf();
$result = $this->promptsUseCase->duplicate((int) $id);
// HTMX request handling
if ($this->isHtmxRequest()) {
if (!$result->success) {
$this->htmxError($result->message);
return;
}
$this->htmxRedirect('/prompts/' . $result->id . '/edit');
return;
}
// Traditional form fallback
if (!$result->success) {
$_SESSION['error'] = $result->message;
$this->redirect('/prompts/' . $id);
}
$_SESSION['success'] = $result->message;
$this->redirect('/prompts/' . $result->id . '/edit');
}
}
Vollständig herunterladen
Aktionen
Andere Versionen dieser Datei
| ID |
Version |
Typ |
Größe |
Datum |
| 1752 |
17 |
modified |
5.3 KB |
2025-12-27 12:46 |
| 1749 |
16 |
modified |
4.9 KB |
2025-12-27 12:45 |
| 1670 |
15 |
modified |
4.6 KB |
2025-12-27 11:29 |
| 865 |
14 |
modified |
4.6 KB |
2025-12-23 08:50 |
| 689 |
13 |
modified |
4.5 KB |
2025-12-23 07:52 |
| 507 |
12 |
modified |
4.6 KB |
2025-12-22 15:42 |
| 506 |
11 |
modified |
4.6 KB |
2025-12-22 15:42 |
| 505 |
10 |
modified |
4.7 KB |
2025-12-22 15:42 |
| 486 |
9 |
modified |
4.4 KB |
2025-12-22 15:26 |
| 485 |
8 |
modified |
4.2 KB |
2025-12-22 15:26 |
| 484 |
7 |
modified |
4.1 KB |
2025-12-22 15:26 |
| 462 |
6 |
modified |
4.1 KB |
2025-12-22 10:30 |
| 461 |
5 |
modified |
4.1 KB |
2025-12-22 10:30 |
| 460 |
4 |
modified |
4.1 KB |
2025-12-22 10:30 |
| 451 |
3 |
modified |
4.7 KB |
2025-12-22 10:25 |
| 450 |
2 |
modified |
4.6 KB |
2025-12-22 10:24 |
| 444 |
1 |
modified |
7.0 KB |
2025-12-22 10:16 |
← Zurück zur Übersicht