Files
Toiminnanohjaus/app/Modules/Jobs/Application/UseCases/EditTaskComment.php
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

47 lines
1.5 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\Exceptions\InvalidTaskCommentBody;
use App\Modules\Jobs\Domain\Exceptions\NotTaskCommentAuthor;
use App\Modules\Jobs\Domain\Exceptions\TaskCommentNotFound;
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;
/**
* Changes the text of the user's own comment and marks it edited.
*/
final class EditTaskComment
{
public function __construct(
private TaskCommentFinder $finder,
private TaskCommentRepository $comments,
private TransactionManager $transactions,
private Clock $clock,
) {}
/**
* @throws TaskNotFound
* @throws TaskCommentNotFound
* @throws NotTaskCommentAuthor
* @throws InvalidTaskCommentBody
*/
public function execute(int $jobId, int $taskId, int $commentId, int $userId, string $body): void
{
$body = new TaskCommentBody($body);
$this->transactions->run(function () use ($jobId, $taskId, $commentId, $userId, $body): void {
$comment = $this->finder->find($jobId, $taskId, $commentId);
$comment->edit($userId, $body, $this->clock->now());
$this->comments->save($comment);
});
}
}