Files
petriandClaude Sonnet 5.5 4fb8ea1c5f Add comments to tasks
Everyone who may change a task's status (attached subcontractors too)
comments on it on the job page. Authors edit and remove their own
comments; admin and management may remove anyone's
(jobs.remove-any-task-comment). Edited comments show when they were
edited, and task cards show the number of comments.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
2026-11-25 07:31:53 +02:00

45 lines
1.4 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Modules\Jobs\Application\UseCases;
use App\Modules\Jobs\Application\Services\TaskCommentFinder;
use App\Modules\Jobs\Domain\Contracts\TaskCommentRepository;
use App\Modules\Jobs\Domain\Entities\TaskComment;
use App\Modules\Jobs\Domain\Exceptions\InvalidTaskCommentBody;
use App\Modules\Jobs\Domain\Exceptions\TaskNotFound;
use App\Modules\Jobs\Domain\ValueObjects\TaskCommentBody;
use App\Modules\Shared\Application\Contracts\TransactionManager;
use App\Modules\Users\Application\Contracts\Clock;
/**
* Adds a comment by the given user to a task.
*/
final class AddTaskComment
{
public function __construct(
private TaskCommentFinder $finder,
private TaskCommentRepository $comments,
private TransactionManager $transactions,
private Clock $clock,
) {}
/**
* @return int The new comment's id.
*
* @throws TaskNotFound
* @throws InvalidTaskCommentBody
*/
public function execute(int $jobId, int $taskId, int $userId, string $body): int
{
$body = new TaskCommentBody($body);
return $this->transactions->run(function () use ($jobId, $taskId, $userId, $body): int {
$this->finder->ensureTask($jobId, $taskId);
return (int) $this->comments->save(TaskComment::create($taskId, $userId, $body, $this->clock->now()))->id();
});
}
}