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,27 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Modules\Jobs\Domain\Contracts;
|
||||
|
||||
use App\Modules\Jobs\Domain\Entities\ChecklistItem;
|
||||
use App\Modules\Jobs\Domain\Enums\MoveDirection;
|
||||
|
||||
interface ChecklistItemRepository
|
||||
{
|
||||
/**
|
||||
* Null when the item does not exist or belongs to another task.
|
||||
*/
|
||||
public function findForTask(int $taskId, int $itemId): ?ChecklistItem;
|
||||
|
||||
/**
|
||||
* The item next to the given one in the task's order, or null at the end.
|
||||
*/
|
||||
public function neighbour(ChecklistItem $item, MoveDirection $direction): ?ChecklistItem;
|
||||
|
||||
public function nextSortOrder(int $taskId): int;
|
||||
|
||||
public function save(ChecklistItem $item): ChecklistItem;
|
||||
|
||||
public function delete(ChecklistItem $item): void;
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Modules\Jobs\Domain\Entities;
|
||||
|
||||
use App\Modules\Jobs\Domain\ValueObjects\ChecklistItemText;
|
||||
use DateTimeImmutable;
|
||||
|
||||
/**
|
||||
* One item of a task's checklist (todo), checked done by someone or not.
|
||||
*/
|
||||
final class ChecklistItem
|
||||
{
|
||||
private function __construct(
|
||||
private ?int $id,
|
||||
private int $taskId,
|
||||
private ChecklistItemText $text,
|
||||
private int $sortOrder,
|
||||
private ?DateTimeImmutable $doneAt,
|
||||
private ?int $doneBy,
|
||||
) {}
|
||||
|
||||
public static function create(int $taskId, ChecklistItemText $text, int $sortOrder): self
|
||||
{
|
||||
return new self(null, $taskId, $text, $sortOrder, null, null);
|
||||
}
|
||||
|
||||
public static function reconstitute(int $id, int $taskId, ChecklistItemText $text, int $sortOrder, ?DateTimeImmutable $doneAt, ?int $doneBy): self
|
||||
{
|
||||
return new self($id, $taskId, $text, $sortOrder, $doneAt, $doneBy);
|
||||
}
|
||||
|
||||
public function rename(ChecklistItemText $text): void
|
||||
{
|
||||
$this->text = $text;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checking an item that already is done keeps who did it and when.
|
||||
*/
|
||||
public function check(int $userId, DateTimeImmutable $at): void
|
||||
{
|
||||
if ($this->doneAt !== null) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->doneAt = $at;
|
||||
$this->doneBy = $userId;
|
||||
}
|
||||
|
||||
public function uncheck(): void
|
||||
{
|
||||
$this->doneAt = null;
|
||||
$this->doneBy = null;
|
||||
}
|
||||
|
||||
public function swapOrderWith(self $other): void
|
||||
{
|
||||
[$this->sortOrder, $other->sortOrder] = [$other->sortOrder, $this->sortOrder];
|
||||
}
|
||||
|
||||
public function id(): ?int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function taskId(): int
|
||||
{
|
||||
return $this->taskId;
|
||||
}
|
||||
|
||||
public function text(): ChecklistItemText
|
||||
{
|
||||
return $this->text;
|
||||
}
|
||||
|
||||
public function sortOrder(): int
|
||||
{
|
||||
return $this->sortOrder;
|
||||
}
|
||||
|
||||
public function isDone(): bool
|
||||
{
|
||||
return $this->doneAt !== null;
|
||||
}
|
||||
|
||||
public function doneAt(): ?DateTimeImmutable
|
||||
{
|
||||
return $this->doneAt;
|
||||
}
|
||||
|
||||
public function doneBy(): ?int
|
||||
{
|
||||
return $this->doneBy;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Modules\Jobs\Domain\Enums;
|
||||
|
||||
enum MoveDirection: string
|
||||
{
|
||||
case Up = 'up';
|
||||
case Down = 'down';
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Modules\Jobs\Domain\Exceptions;
|
||||
|
||||
use App\Modules\Shared\Domain\Exceptions\DomainException;
|
||||
|
||||
/**
|
||||
* The checklist item does not exist or belongs to another task or job.
|
||||
*/
|
||||
final class ChecklistItemNotFound extends DomainException
|
||||
{
|
||||
public function __construct(public readonly int $taskId, public readonly int $itemId)
|
||||
{
|
||||
parent::__construct("Checklist item {$itemId} of task {$taskId} was not found.");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Modules\Jobs\Domain\Exceptions;
|
||||
|
||||
use App\Modules\Shared\Domain\Exceptions\DomainException;
|
||||
|
||||
final class InvalidChecklistItemText extends DomainException
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct('A checklist item must be 1–255 characters.');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Modules\Jobs\Domain\ValueObjects;
|
||||
|
||||
use App\Modules\Jobs\Domain\Exceptions\InvalidChecklistItemText;
|
||||
|
||||
final readonly class ChecklistItemText
|
||||
{
|
||||
public const int MAX_LENGTH = 255;
|
||||
|
||||
public string $value;
|
||||
|
||||
/**
|
||||
* @throws InvalidChecklistItemText
|
||||
*/
|
||||
public function __construct(string $value)
|
||||
{
|
||||
$value = trim(preg_replace('/\s+/u', ' ', $value) ?? $value);
|
||||
|
||||
if ($value === '' || mb_strlen($value) > self::MAX_LENGTH) {
|
||||
throw new InvalidChecklistItemText;
|
||||
}
|
||||
|
||||
$this->value = $value;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user