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]>
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Modules\Jobs\Application\Services;
|
||||
|
||||
use App\Modules\Jobs\Domain\Contracts\TaskCommentRepository;
|
||||
use App\Modules\Jobs\Domain\Contracts\TaskRepository;
|
||||
use App\Modules\Jobs\Domain\Entities\TaskComment;
|
||||
use App\Modules\Jobs\Domain\Exceptions\TaskCommentNotFound;
|
||||
use App\Modules\Jobs\Domain\Exceptions\TaskNotFound;
|
||||
|
||||
/**
|
||||
* Finds a comment only through its task and the task's job, so a page of
|
||||
* one job never changes another job's comments.
|
||||
*/
|
||||
final readonly class TaskCommentFinder
|
||||
{
|
||||
public function __construct(
|
||||
private TaskRepository $tasks,
|
||||
private TaskCommentRepository $comments,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* @throws TaskNotFound
|
||||
* @throws TaskCommentNotFound
|
||||
*/
|
||||
public function find(int $jobId, int $taskId, int $commentId): TaskComment
|
||||
{
|
||||
$this->ensureTask($jobId, $taskId);
|
||||
|
||||
return $this->comments->findForTask($taskId, $commentId) ?? throw new TaskCommentNotFound($taskId, $commentId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws TaskNotFound
|
||||
*/
|
||||
public function ensureTask(int $jobId, int $taskId): void
|
||||
{
|
||||
if ($this->tasks->findForJob($jobId, $taskId) === null) {
|
||||
throw new TaskNotFound($jobId, $taskId);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user