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]>
49 lines
1.4 KiB
PHP
49 lines
1.4 KiB
PHP
<?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\Enums\MoveDirection;
|
|
use App\Modules\Jobs\Domain\Exceptions\ChecklistItemNotFound;
|
|
use App\Modules\Jobs\Domain\Exceptions\TaskNotFound;
|
|
use App\Modules\Shared\Application\Contracts\TransactionManager;
|
|
|
|
/**
|
|
* Moves a checklist item one place up or down.
|
|
*/
|
|
final class MoveChecklistItem
|
|
{
|
|
public function __construct(
|
|
private ChecklistItemFinder $finder,
|
|
private ChecklistItemRepository $items,
|
|
private TransactionManager $transactions,
|
|
) {}
|
|
|
|
/**
|
|
* @return bool False when the item already was first (up) or last (down).
|
|
*
|
|
* @throws TaskNotFound
|
|
* @throws ChecklistItemNotFound
|
|
*/
|
|
public function execute(int $jobId, int $taskId, int $itemId, MoveDirection $direction): bool
|
|
{
|
|
return $this->transactions->run(function () use ($jobId, $taskId, $itemId, $direction): bool {
|
|
$item = $this->finder->find($jobId, $taskId, $itemId);
|
|
$neighbour = $this->items->neighbour($item, $direction);
|
|
|
|
if ($neighbour === null) {
|
|
return false;
|
|
}
|
|
|
|
$item->swapOrderWith($neighbour);
|
|
$this->items->save($item);
|
|
$this->items->save($neighbour);
|
|
|
|
return true;
|
|
});
|
|
}
|
|
}
|