Backup #705
| ID | 705 |
| Dateipfad | /var/www/dev.campus.systemische-tools.de/src/UseCases/Task/CreateTaskUseCase.php |
| Version | 1 |
| Typ |
modified |
| Größe | 2.4 KB |
| Hash | b34582a93362f6dc0cd63ea0d1af27e16932bd7789abc9690dc24e76f7fc2331 |
| Datum | 2025-12-23 07:54:33 |
| Geändert von | claude-code-hook |
| Grund | Claude Code Pre-Hook Backup vor Edit-Operation |
| Datei existiert |
Ja
|
Dateiinhalt
<?php
namespace UseCases\Task;
use Domain\Entity\Task;
use Domain\Entity\TaskComment;
use Infrastructure\Persistence\TaskCommentRepository;
use Infrastructure\Persistence\TaskRepository;
class CreateTaskUseCase
{
private TaskRepository $taskRepository;
private TaskCommentRepository $commentRepository;
public function __construct(
?TaskRepository $taskRepository = null,
?TaskCommentRepository $commentRepository = null
) {
$this->taskRepository = $taskRepository ?? new TaskRepository();
$this->commentRepository = $commentRepository ?? new TaskCommentRepository();
}
public function execute(array $data): Task
{
$this->validate($data);
$task = new Task();
$task->setTitle($data['title']);
$task->setCreatedBy($data['created_by'] ?? 'system');
$task->setCreatedByType($data['created_by_type'] ?? 'human');
if (isset($data['description'])) {
$task->setDescription($data['description']);
}
if (isset($data['type'])) {
$task->setType($data['type']);
}
if (isset($data['parent_task_id'])) {
$task->setParentTaskId((int) $data['parent_task_id']);
}
if (isset($data['due_date'])) {
$task->setDueDate(new \DateTimeImmutable($data['due_date']));
}
if (isset($data['metadata'])) {
$task->setMetadata($data['metadata']);
}
$id = $this->taskRepository->save($task);
$task->setId($id);
$comment = new TaskComment();
$comment->setTaskId($id);
$comment->setAuthor($task->getCreatedBy());
$comment->setAuthorType($task->getCreatedByType());
$comment->setCommentType('note');
$comment->setContent('Task erstellt');
$this->commentRepository->save($comment);
return $task;
}
private function validate(array $data): void
{
if (!isset($data['title']) || $data['title'] === '') {
throw new \InvalidArgumentException('Title is required');
}
if (strlen($data['title']) > 255) {
throw new \InvalidArgumentException('Title must be 255 characters or less');
}
if (isset($data['type']) && !in_array($data['type'], ['human_task', 'ai_task', 'mixed'])) {
throw new \InvalidArgumentException('Invalid task type');
}
}
}
Vollständig herunterladen
Aktionen
Andere Versionen dieser Datei
| ID |
Version |
Typ |
Größe |
Datum |
| 1475 |
6 |
modified |
2.1 KB |
2025-12-25 17:02 |
| 1474 |
5 |
modified |
2.0 KB |
2025-12-25 17:02 |
| 1463 |
4 |
modified |
2.3 KB |
2025-12-25 17:01 |
| 1460 |
3 |
modified |
2.2 KB |
2025-12-25 17:01 |
| 827 |
2 |
modified |
2.5 KB |
2025-12-23 08:14 |
| 705 |
1 |
modified |
2.4 KB |
2025-12-23 07:54 |
← Zurück zur Übersicht