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,18 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Modules\Jobs\Application\Contracts;
|
||||
|
||||
use App\Modules\Jobs\Application\DTOs\ChecklistItemSummary;
|
||||
|
||||
interface ChecklistQueries
|
||||
{
|
||||
/**
|
||||
* The task's checklist in its order; empty when the task belongs to
|
||||
* another job.
|
||||
*
|
||||
* @return list<ChecklistItemSummary>
|
||||
*/
|
||||
public function checklistOf(int $jobId, int $taskId): array;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Modules\Jobs\Application\DTOs;
|
||||
|
||||
final readonly class ChecklistItemSummary
|
||||
{
|
||||
public function __construct(
|
||||
public int $id,
|
||||
public string $text,
|
||||
public bool $done,
|
||||
) {}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
<?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\Exceptions\ChecklistItemNotFound;
|
||||
use App\Modules\Jobs\Domain\Exceptions\TaskNotFound;
|
||||
use App\Modules\Shared\Application\Contracts\TransactionManager;
|
||||
use App\Modules\Users\Application\Contracts\Clock;
|
||||
|
||||
/**
|
||||
* Marks a checklist item done (recording who and when) or not done.
|
||||
*/
|
||||
final class CheckChecklistItem
|
||||
{
|
||||
public function __construct(
|
||||
private ChecklistItemFinder $finder,
|
||||
private ChecklistItemRepository $items,
|
||||
private TransactionManager $transactions,
|
||||
private Clock $clock,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* @throws TaskNotFound
|
||||
* @throws ChecklistItemNotFound
|
||||
*/
|
||||
public function execute(int $jobId, int $taskId, int $itemId, bool $done, int $userId): void
|
||||
{
|
||||
$this->transactions->run(function () use ($jobId, $taskId, $itemId, $done, $userId): void {
|
||||
$item = $this->finder->find($jobId, $taskId, $itemId);
|
||||
|
||||
if ($done) {
|
||||
$item->check($userId, $this->clock->now());
|
||||
} else {
|
||||
$item->uncheck();
|
||||
}
|
||||
|
||||
$this->items->save($item);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
<?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;
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
<?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\Exceptions\ChecklistItemNotFound;
|
||||
use App\Modules\Jobs\Domain\Exceptions\TaskNotFound;
|
||||
use App\Modules\Shared\Application\Contracts\TransactionManager;
|
||||
|
||||
final class RemoveChecklistItem
|
||||
{
|
||||
public function __construct(
|
||||
private ChecklistItemFinder $finder,
|
||||
private ChecklistItemRepository $items,
|
||||
private TransactionManager $transactions,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* @throws TaskNotFound
|
||||
* @throws ChecklistItemNotFound
|
||||
*/
|
||||
public function execute(int $jobId, int $taskId, int $itemId): void
|
||||
{
|
||||
$this->transactions->run(function () use ($jobId, $taskId, $itemId): void {
|
||||
$this->items->delete($this->finder->find($jobId, $taskId, $itemId));
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
<?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\Exceptions\ChecklistItemNotFound;
|
||||
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;
|
||||
|
||||
final class RenameChecklistItem
|
||||
{
|
||||
public function __construct(
|
||||
private ChecklistItemFinder $finder,
|
||||
private ChecklistItemRepository $items,
|
||||
private TransactionManager $transactions,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* @throws TaskNotFound
|
||||
* @throws ChecklistItemNotFound
|
||||
* @throws InvalidChecklistItemText
|
||||
*/
|
||||
public function execute(int $jobId, int $taskId, int $itemId, string $text): void
|
||||
{
|
||||
$text = new ChecklistItemText($text);
|
||||
|
||||
$this->transactions->run(function () use ($jobId, $taskId, $itemId, $text): void {
|
||||
$item = $this->finder->find($jobId, $taskId, $itemId);
|
||||
$item->rename($text);
|
||||
$this->items->save($item);
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user