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:
+73
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
namespace App\Modules\Jobs\Infrastructure\Persistence\Repositories;
|
||||
|
||||
use App\Modules\Jobs\Domain\Contracts\ChecklistItemRepository;
|
||||
use App\Modules\Jobs\Domain\Entities\ChecklistItem;
|
||||
use App\Modules\Jobs\Domain\Enums\MoveDirection;
|
||||
use App\Modules\Jobs\Domain\ValueObjects\ChecklistItemText;
|
||||
use App\Modules\Jobs\Infrastructure\Persistence\Eloquent\ChecklistItemModel;
|
||||
use DateTimeImmutable;
|
||||
|
||||
class EloquentChecklistItemRepository implements ChecklistItemRepository
|
||||
{
|
||||
public function findForTask(int $taskId, int $itemId): ?ChecklistItem
|
||||
{
|
||||
$model = ChecklistItemModel::query()->where('task_id', $taskId)->find($itemId);
|
||||
|
||||
return $model === null ? null : $this->toEntity($model);
|
||||
}
|
||||
|
||||
public function neighbour(ChecklistItem $item, MoveDirection $direction): ?ChecklistItem
|
||||
{
|
||||
$up = $direction === MoveDirection::Up;
|
||||
$model = ChecklistItemModel::query()
|
||||
->where('task_id', $item->taskId())
|
||||
->whereKeyNot($item->id())
|
||||
->where(fn ($query) => $query
|
||||
->where('sort_order', $up ? '<' : '>', $item->sortOrder())
|
||||
->orWhere(fn ($query) => $query->where('sort_order', $item->sortOrder())->where('id', $up ? '<' : '>', $item->id())))
|
||||
->orderBy('sort_order', $up ? 'desc' : 'asc')
|
||||
->orderBy('id', $up ? 'desc' : 'asc')
|
||||
->first();
|
||||
|
||||
return $model === null ? null : $this->toEntity($model);
|
||||
}
|
||||
|
||||
public function nextSortOrder(int $taskId): int
|
||||
{
|
||||
return (int) ChecklistItemModel::query()->where('task_id', $taskId)->max('sort_order') + 1;
|
||||
}
|
||||
|
||||
public function save(ChecklistItem $item): ChecklistItem
|
||||
{
|
||||
$model = $item->id() === null ? new ChecklistItemModel : ChecklistItemModel::query()->findOrFail($item->id());
|
||||
|
||||
$model->fill([
|
||||
'task_id' => $item->taskId(),
|
||||
'text' => $item->text()->value,
|
||||
'sort_order' => $item->sortOrder(),
|
||||
'done_at' => $item->doneAt()?->format('Y-m-d H:i:s'),
|
||||
'done_by' => $item->doneBy(),
|
||||
])->save();
|
||||
|
||||
return $this->toEntity($model->refresh());
|
||||
}
|
||||
|
||||
public function delete(ChecklistItem $item): void
|
||||
{
|
||||
ChecklistItemModel::query()->whereKey($item->id())->delete();
|
||||
}
|
||||
|
||||
private function toEntity(ChecklistItemModel $model): ChecklistItem
|
||||
{
|
||||
return ChecklistItem::reconstitute(
|
||||
$model->id,
|
||||
$model->task_id,
|
||||
new ChecklistItemText($model->text),
|
||||
$model->sort_order,
|
||||
$model->done_at === null ? null : DateTimeImmutable::createFromInterface($model->done_at),
|
||||
$model->done_by,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Modules\Jobs\Infrastructure\Persistence\Repositories;
|
||||
|
||||
use App\Modules\Jobs\Application\Contracts\ChecklistQueries;
|
||||
use App\Modules\Jobs\Application\DTOs\ChecklistItemSummary;
|
||||
use App\Modules\Jobs\Infrastructure\Persistence\Eloquent\ChecklistItemModel;
|
||||
|
||||
class EloquentChecklistQueries implements ChecklistQueries
|
||||
{
|
||||
public function checklistOf(int $jobId, int $taskId): array
|
||||
{
|
||||
return ChecklistItemModel::query()
|
||||
->where('task_id', $taskId)
|
||||
->whereExists(fn ($query) => $query->selectRaw('1')->from('tasks')
|
||||
->whereColumn('tasks.id', 'task_checklist_items.task_id')
|
||||
->where('tasks.customer_job_id', $jobId))
|
||||
->orderBy('sort_order')
|
||||
->orderBy('id')
|
||||
->get()
|
||||
->map(fn (ChecklistItemModel $model): ChecklistItemSummary => new ChecklistItemSummary($model->id, $model->text, $model->done_at !== null))
|
||||
->values()
|
||||
->all();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user