Add checklists to tasks on the job page
Tasks get an ordered checklist (spec 8.2, phase 3): items are checked done with who and when recorded, also by subcontractors attached to the job; others add, rename, reorder and remove items. Items go with their task. The spec gets a phase 3 chapter (18.1), and open questions move to chapter 19. Co-Authored-By: Claude Opus 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\ChecklistItemRepository;
|
||||
use App\Modules\Jobs\Domain\Contracts\TaskRepository;
|
||||
use App\Modules\Jobs\Domain\Entities\ChecklistItem;
|
||||
use App\Modules\Jobs\Domain\Exceptions\ChecklistItemNotFound;
|
||||
use App\Modules\Jobs\Domain\Exceptions\TaskNotFound;
|
||||
|
||||
/**
|
||||
* Finds a checklist item only through its task and the task's job, so a
|
||||
* page of one job never changes another job's items.
|
||||
*/
|
||||
final readonly class ChecklistItemFinder
|
||||
{
|
||||
public function __construct(
|
||||
private TaskRepository $tasks,
|
||||
private ChecklistItemRepository $items,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* @throws TaskNotFound
|
||||
* @throws ChecklistItemNotFound
|
||||
*/
|
||||
public function find(int $jobId, int $taskId, int $itemId): ChecklistItem
|
||||
{
|
||||
$this->ensureTask($jobId, $taskId);
|
||||
|
||||
return $this->items->findForTask($taskId, $itemId) ?? throw new ChecklistItemNotFound($taskId, $itemId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @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