Add catalog module for service units, services and work types

Phase 1, item 3: the hierarchy customer jobs, tasks and time entries
will refer to.

- New Catalog module: service unit > optional service > work type.
  Names are unique per level (case-insensitive); items are never
  deleted, only deactivated, and foreign keys restrict deletes.
- Pohjatiedot page (/catalog, admins and management): add, rename,
  reorder with move up/down buttons (keyboard-friendly, focus kept and
  announced) and an "in use" checkbox per row. Work types can move to
  another service of the same unit.
- A migration inserts the starting catalog from the specification when
  the tables are empty, so every installation has it.
- CatalogQueries gives other modules the active service units and the
  work types of chosen units plus the shared ones.
- Spec and CLAUDE.md updated.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
2026-11-23 18:27:58 +02:00
co-authored by Claude Opus 5.5
parent e0b8f4970f
commit 51b2d4a252
62 changed files with 3196 additions and 7 deletions
@@ -0,0 +1,83 @@
<?php
declare(strict_types=1);
namespace App\Modules\Catalog\Application\UseCases;
use App\Modules\Catalog\Domain\Contracts\ServiceRepository;
use App\Modules\Catalog\Domain\Contracts\ServiceUnitRepository;
use App\Modules\Catalog\Domain\Contracts\WorkTypeRepository;
use App\Modules\Catalog\Domain\Entities\Service;
use App\Modules\Catalog\Domain\Entities\ServiceUnit;
use App\Modules\Catalog\Domain\Entities\WorkType;
use App\Modules\Catalog\Domain\Enums\CatalogLevel;
use App\Modules\Catalog\Domain\Enums\MoveDirection;
use App\Modules\Catalog\Domain\Exceptions\CatalogItemNotFound;
use App\Modules\Shared\Application\Contracts\TransactionManager;
/**
* Moves an item one place up or down among its siblings.
*/
final class MoveCatalogItem
{
public function __construct(
private ServiceUnitRepository $serviceUnits,
private ServiceRepository $services,
private WorkTypeRepository $workTypes,
private TransactionManager $transactions,
) {}
/**
* @return bool False when the item already was first (up) or last (down).
*
* @throws CatalogItemNotFound
*/
public function execute(CatalogLevel $level, int $id, MoveDirection $direction): bool
{
return $this->transactions->run(fn (): bool => match ($level) {
CatalogLevel::ServiceUnit => $this->moveServiceUnit($id, $direction),
CatalogLevel::Service => $this->moveService($id, $direction),
CatalogLevel::WorkType => $this->moveWorkType($id, $direction),
});
}
private function moveServiceUnit(int $id, MoveDirection $direction): bool
{
$item = $this->serviceUnits->findById($id) ?? throw new CatalogItemNotFound(CatalogLevel::ServiceUnit, $id);
$neighbour = $this->serviceUnits->neighbour($item, $direction);
return $neighbour !== null && $this->swap($item, $neighbour, fn (ServiceUnit $unit) => $this->serviceUnits->save($unit));
}
private function moveService(int $id, MoveDirection $direction): bool
{
$item = $this->services->findById($id) ?? throw new CatalogItemNotFound(CatalogLevel::Service, $id);
$neighbour = $this->services->neighbour($item, $direction);
return $neighbour !== null && $this->swap($item, $neighbour, fn (Service $service) => $this->services->save($service));
}
private function moveWorkType(int $id, MoveDirection $direction): bool
{
$item = $this->workTypes->findById($id) ?? throw new CatalogItemNotFound(CatalogLevel::WorkType, $id);
$neighbour = $this->workTypes->neighbour($item, $direction);
return $neighbour !== null && $this->swap($item, $neighbour, fn (WorkType $workType) => $this->workTypes->save($workType));
}
/**
* @template T of ServiceUnit|Service|WorkType
*
* @param T $item
* @param T $neighbour
* @param callable(T): mixed $save
*/
private function swap(ServiceUnit|Service|WorkType $item, ServiceUnit|Service|WorkType $neighbour, callable $save): bool
{
$item->swapOrderWith($neighbour);
$save($item);
$save($neighbour);
return true;
}
}