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,42 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Modules\Jobs\Application\UseCases;
|
||||
|
||||
use App\Modules\Jobs\Application\Services\ChecklistItemFinder;
|
||||
use App\Modules\Jobs\Domain\Contracts\ChecklistItemRepository;
|
||||
use App\Modules\Jobs\Domain\Entities\ChecklistItem;
|
||||
use App\Modules\Jobs\Domain\Exceptions\InvalidChecklistItemText;
|
||||
use App\Modules\Jobs\Domain\Exceptions\TaskNotFound;
|
||||
use App\Modules\Jobs\Domain\ValueObjects\ChecklistItemText;
|
||||
use App\Modules\Shared\Application\Contracts\TransactionManager;
|
||||
|
||||
/**
|
||||
* Adds an item to the end of a task's checklist.
|
||||
*/
|
||||
final class AddChecklistItem
|
||||
{
|
||||
public function __construct(
|
||||
private ChecklistItemFinder $finder,
|
||||
private ChecklistItemRepository $items,
|
||||
private TransactionManager $transactions,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* @return int The new item's id.
|
||||
*
|
||||
* @throws TaskNotFound
|
||||
* @throws InvalidChecklistItemText
|
||||
*/
|
||||
public function execute(int $jobId, int $taskId, string $text): int
|
||||
{
|
||||
$text = new ChecklistItemText($text);
|
||||
|
||||
return $this->transactions->run(function () use ($jobId, $taskId, $text): int {
|
||||
$this->finder->ensureTask($jobId, $taskId);
|
||||
|
||||
return (int) $this->items->save(ChecklistItem::create($taskId, $text, $this->items->nextSortOrder($taskId)))->id();
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user