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:
@@ -0,0 +1,49 @@
|
||||
<?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\Entities\Service;
|
||||
use App\Modules\Catalog\Domain\Enums\CatalogLevel;
|
||||
use App\Modules\Catalog\Domain\Exceptions\CatalogItemNotFound;
|
||||
use App\Modules\Catalog\Domain\Exceptions\CatalogNameTaken;
|
||||
use App\Modules\Catalog\Domain\Exceptions\SharedUnitHasNoServices;
|
||||
use App\Modules\Catalog\Domain\ValueObjects\CatalogName;
|
||||
use App\Modules\Shared\Application\Contracts\TransactionManager;
|
||||
|
||||
final class AddService
|
||||
{
|
||||
public function __construct(
|
||||
private ServiceUnitRepository $serviceUnits,
|
||||
private ServiceRepository $services,
|
||||
private TransactionManager $transactions,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* @return int The new service's id.
|
||||
*
|
||||
* @throws CatalogItemNotFound
|
||||
* @throws CatalogNameTaken
|
||||
* @throws SharedUnitHasNoServices
|
||||
*/
|
||||
public function execute(int $serviceUnitId, string $name): int
|
||||
{
|
||||
$name = new CatalogName($name);
|
||||
|
||||
return $this->transactions->run(function () use ($serviceUnitId, $name): int {
|
||||
$serviceUnit = $this->serviceUnits->findById($serviceUnitId)
|
||||
?? throw new CatalogItemNotFound(CatalogLevel::ServiceUnit, $serviceUnitId);
|
||||
|
||||
if ($this->services->isNameTaken($serviceUnitId, $name->value)) {
|
||||
throw new CatalogNameTaken;
|
||||
}
|
||||
|
||||
$service = Service::create($serviceUnit, $name, $this->services->nextSortOrder($serviceUnitId));
|
||||
|
||||
return (int) $this->services->save($service)->id();
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user