feat(catalog): manage global categories from settings

Categories are the taxonomy both services and resources select from, but
until now they could only be reached through the service catalog, so every
environment ended up with its own spelling of "whole body".

- Settings > Categories page: global CRUD plus the "includes" edge
- POST/GET/DELETE /api/v1/service-category/{uuid}/includes — a DAG, kept
  separate from `parent` because "hand" sits under both "whole body" and
  "upper limb"; a cycle is refused with 422
- PUT /api/v1/resource/{uuid}/categories — full replacement, and a category
  from another environment is rejected explicitly since the uuid arrives in
  the request body where TenantFilter does not reach

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
hamed
2026-08-02 12:58:26 +03:30
co-authored by Claude Opus 5
parent f8e8a63ae8
commit 03d8d7d68a
13 changed files with 865 additions and 0 deletions
+38
View File
@@ -16,8 +16,46 @@ final class ResourceService
public function __construct(
private readonly EntityManagerInterface $em,
private readonly \App\ClinicService\Repository\CatalogCategoryRepository $categories,
) {}
/**
* دسته‌های این منبع — جایگزینی کامل.
*
* دسته فقط **انتخاب** می‌شود؛ ساختش کار صفحهٔ «تنظیمات ← دسته‌بندی‌ها» است. دستهٔ
* محیط دیگر رد می‌شود چون uuid از بدنهٔ درخواست می‌آید و `TenantFilter` پوششش نمی‌دهد.
*
* @param list<mixed> $categoryUuids
* @throws AppException ۴۲۲ روی دستهٔ ناموجود یا دستهٔ محیط دیگر
*/
public function replaceCategories(ClinicResource $resource, array $categoryUuids): void
{
$chosen = [];
foreach ($categoryUuids as $uuid) {
if (!is_string($uuid) || trim($uuid) === '') {
continue;
}
$category = $this->categories->findOneBy(['uuid' => trim($uuid)]);
if ($category === null
|| $category->getEntityType() !== $resource->getEntityType()
|| $category->getEntityId() !== $resource->getEntityId()) {
throw new AppException(ErrorCodes::ERR_VALIDATION_002, 'دسته‌بندی یافت نشد', 422, 'category_uuids');
}
$chosen[(int) $category->getId()] = $category;
}
$resource->getCategories()->clear();
foreach ($chosen as $category) {
$resource->getCategories()->add($category);
}
$this->em->flush();
}
/** @param array<string, mixed> $data */
public function create(DoctorAddress $address, ResourceType $type, array $data): ClinicResource
{