Backup #114
| ID | 114 |
| Dateipfad | /var/www/dev.campus.systemische-tools.de/src/Controller/Api/TaskController.php |
| Version | 1 |
| Typ |
modified |
| Größe | 8.2 KB |
| Hash | a80eef8b1dafe39162f9bb455c514a5dd81ee70e15ec6af68d8ab427cacb4fec |
| Datum | 2025-12-20 19:20:33 |
| Geändert von | claude-code-hook |
| Grund | Claude Code Pre-Hook Backup vor Edit-Operation |
| Datei existiert |
Ja
|
Dateiinhalt
<?php
namespace Controller\Api;
use Framework\Controller;
use UseCases\Task\AssignTaskUseCase;
use UseCases\Task\CreateTaskUseCase;
use UseCases\Task\DeleteTaskUseCase;
use UseCases\Task\ExecuteAITaskUseCase;
use UseCases\Task\GetTasksUseCase;
use UseCases\Task\SaveTaskResultUseCase;
use UseCases\Task\UpdateTaskStatusUseCase;
class TaskController extends Controller
{
public function index(): void
{
try {
$filters = [];
if (isset($_GET['status']) && $_GET['status'] !== '') {
$filters['status'] = $_GET['status'];
}
if (isset($_GET['type']) && $_GET['type'] !== '') {
$filters['type'] = $_GET['type'];
}
if (isset($_GET['search']) && $_GET['search'] !== '') {
$filters['search'] = $_GET['search'];
}
$limit = (int) ($_GET['limit'] ?? 50);
$offset = (int) ($_GET['offset'] ?? 0);
$useCase = new GetTasksUseCase();
$tasks = $useCase->execute($filters, $limit, $offset);
$total = $useCase->count($filters);
$this->json([
'success' => true,
'data' => array_map(fn ($t) => $t->toArray(), $tasks),
'meta' => [
'total' => $total,
'limit' => $limit,
'offset' => $offset,
],
]);
} catch (\Exception $e) {
$this->jsonError($e->getMessage());
}
}
public function show(string $id): void
{
try {
$useCase = new GetTasksUseCase();
$details = $useCase->getTaskWithDetails((int) $id);
if ($details === null) {
$this->json(['success' => false, 'error' => 'Task not found'], 404);
return;
}
$this->json([
'success' => true,
'data' => $details,
]);
} catch (\Exception $e) {
$this->jsonError($e->getMessage());
}
}
public function store(): void
{
try {
$input = $this->getJsonInput();
$useCase = new CreateTaskUseCase();
$task = $useCase->execute($input);
$this->json([
'success' => true,
'data' => $task->toArray(),
], 201);
} catch (\InvalidArgumentException $e) {
$this->json(['success' => false, 'error' => $e->getMessage()], 400);
} catch (\Exception $e) {
$this->jsonError($e->getMessage());
}
}
public function update(string $id): void
{
try {
$input = $this->getJsonInput();
$useCase = new GetTasksUseCase();
$task = $useCase->findById((int) $id);
if ($task === null) {
$this->json(['success' => false, 'error' => 'Task not found'], 404);
return;
}
if (isset($input['title'])) {
$task->setTitle($input['title']);
}
if (isset($input['description'])) {
$task->setDescription($input['description']);
}
if (isset($input['type'])) {
$task->setType($input['type']);
}
if (isset($input['due_date'])) {
$task->setDueDate(new \DateTimeImmutable($input['due_date']));
}
$repo = new \Infrastructure\Persistence\TaskRepository();
$repo->update($task);
$this->json([
'success' => true,
'data' => $task->toArray(),
]);
} catch (\InvalidArgumentException $e) {
$this->json(['success' => false, 'error' => $e->getMessage()], 400);
} catch (\Exception $e) {
$this->jsonError($e->getMessage());
}
}
public function destroy(string $id): void
{
try {
$useCase = new DeleteTaskUseCase();
$useCase->execute((int) $id);
$this->json([
'success' => true,
'message' => 'Task deleted',
]);
} catch (\InvalidArgumentException $e) {
$this->json(['success' => false, 'error' => $e->getMessage()], 404);
} catch (\Exception $e) {
$this->jsonError($e->getMessage());
}
}
public function assign(string $id): void
{
try {
$input = $this->getJsonInput();
$useCase = new AssignTaskUseCase();
$assignment = $useCase->execute((int) $id, $input);
$this->json([
'success' => true,
'data' => $assignment->toArray(),
], 201);
} catch (\InvalidArgumentException $e) {
$this->json(['success' => false, 'error' => $e->getMessage()], 400);
} catch (\Exception $e) {
$this->jsonError($e->getMessage());
}
}
public function updateStatus(string $id): void
{
try {
$input = $this->getJsonInput();
if (!isset($input['status']) || $input['status'] === '') {
$this->json(['success' => false, 'error' => 'Status is required'], 400);
return;
}
$updatedBy = $input['updated_by'] ?? 'api';
$updatedByType = $input['updated_by_type'] ?? 'human';
$useCase = new UpdateTaskStatusUseCase();
$task = $useCase->execute((int) $id, $input['status'], $updatedBy, $updatedByType);
$this->json([
'success' => true,
'data' => $task->toArray(),
]);
} catch (\InvalidArgumentException $e) {
$this->json(['success' => false, 'error' => $e->getMessage()], 400);
} catch (\Exception $e) {
$this->jsonError($e->getMessage());
}
}
public function storeResult(string $id): void
{
try {
$input = $this->getJsonInput();
$useCase = new SaveTaskResultUseCase();
$result = $useCase->execute((int) $id, $input);
$this->json([
'success' => true,
'data' => $result->toArray(),
], 201);
} catch (\InvalidArgumentException $e) {
$this->json(['success' => false, 'error' => $e->getMessage()], 400);
} catch (\Exception $e) {
$this->jsonError($e->getMessage());
}
}
public function getResults(string $id): void
{
try {
$repo = new \Infrastructure\Persistence\TaskResultRepository();
$results = $repo->findByTaskId((int) $id);
$this->json([
'success' => true,
'data' => array_map(fn ($r) => $r->toArray(), $results),
]);
} catch (\Exception $e) {
$this->jsonError($e->getMessage());
}
}
public function executeAI(string $id): void
{
try {
$input = $this->getJsonInput();
$useCase = new ExecuteAITaskUseCase();
$result = $useCase->execute((int) $id, $input);
$this->json([
'success' => true,
'data' => $result->toArray(),
]);
} catch (\InvalidArgumentException $e) {
$this->json(['success' => false, 'error' => $e->getMessage()], 400);
} catch (\RuntimeException $e) {
$this->json(['success' => false, 'error' => $e->getMessage()], 503);
} catch (\Exception $e) {
$this->jsonError($e->getMessage());
}
}
public function statistics(): void
{
try {
$taskUseCase = new GetTasksUseCase();
$taskStats = $taskUseCase->getStatistics();
$resultRepo = new \Infrastructure\Persistence\TaskResultRepository();
$tokenStats = $resultRepo->getTokenStatistics();
$modelUsage = $resultRepo->getModelUsage();
$this->json([
'success' => true,
'data' => [
'tasks' => $taskStats,
'tokens' => $tokenStats,
'models' => $modelUsage,
],
]);
} catch (\Exception $e) {
$this->jsonError($e->getMessage());
}
}
}
Vollständig herunterladen
Aktionen
Andere Versionen dieser Datei
| ID |
Version |
Typ |
Größe |
Datum |
| 115 |
2 |
modified |
8.2 KB |
2025-12-20 19:20 |
| 114 |
1 |
modified |
8.2 KB |
2025-12-20 19:20 |
← Zurück zur Übersicht