Add cache clearing after key documentation category operations

- Inject `ClearCacheCommandHandler` into `DocumentationCategoryService`.
- Clear cache when creating, updating, or deleting a documentation category.
- Extend responses to include `categoryPath` where applicable.
This commit is contained in:
2026-07-25 01:19:09 +05:00
parent 0d08276d44
commit d925928ea9
@@ -20,6 +20,7 @@ use App\ServiceResults\ServiceResultArray;
use App\ServiceResults\ServiceResultError;
use App\ServiceResults\ServiceResultSuccess;
use App\ServiceResults\StoreUpdateResult;
use App\Services\ClearCacheCommandHandler;
use App\Services\DocumentationCategory\DocumentationCategoryCommandHandler;
use App\Services\DocumentationCategoryContent\ModelSyncCommand;
use App\Services\Service;
@@ -34,6 +35,7 @@ final class DocumentationCategoryService extends Service
private readonly DocumentationCategoryRepository $documentationCategoryRepository,
private readonly DocumentationCategoryCommandHandler $categoryCommandHandler,
private readonly ModelSyncCommand $contentSaveCommand,
private readonly ClearCacheCommandHandler $clearCacheCommandHandler,
) { }
public function index(int $projectId, int $versionId, DocumentationCategoryBuilderDto $documentationCategoryBuilderDto, QuerySettingsDto $querySettingsDto, User $user): ServiceResultError | ServiceResultArray
@@ -89,8 +91,10 @@ final class DocumentationCategoryService extends Service
$defaultLanguage = $project->languages->where('is_default', 1)->first();
$category = new DocumentationCategory();
$categoryPath = null;
if ($parentId !== null) {
$category->parent_id = $parentId;
$categoryPath = $this->documentationCategoryRepository->getPathFromRoot($parentId, $defaultLanguage);
}
return $this->result([
@@ -99,6 +103,7 @@ final class DocumentationCategoryService extends Service
'category' => $category,
'categories' => $this->documentationCategoryRepository->getForSelect($version, $defaultLanguage),
'serviceTranslationEnable' => config('translation_service.enable', false),
'categoryPath' => $categoryPath,
]);
}
@@ -119,17 +124,20 @@ final class DocumentationCategoryService extends Service
return $this->errFobidden(__('Access is denied'));
}
$defaultLanguage = $project->languages->where('is_default', 1)->first();
$withCategories = [];
$categoryPath = null;
if ($category->parent_id) {
$withCategories[] = $category->parent_id;
$categoryPath = $this->documentationCategoryRepository->getPathFromRoot($category->parent_id, $defaultLanguage);
}
$defaultLanguage = $project->languages->where('is_default', 1)->first();
return $this->result([
'version' => $version,
'project' => $project,
'category' => $category,
'categories' => $this->documentationCategoryRepository->getForSelect($version, $defaultLanguage, $category, $withCategories),
'serviceTranslationEnable' => config('translation_service.enable', false),
'categoryPath' => $categoryPath,
]);
}
@@ -165,6 +173,8 @@ final class DocumentationCategoryService extends Service
if (\config('translation_service.enable', false)) {
$this->translateContent($category, $data->getContents());
}
$this->clearCacheCommandHandler->all();
} catch (ServiceException $e) {
return $e->getServiceResultError();
} catch (\Throwable $e) {
@@ -219,6 +229,8 @@ final class DocumentationCategoryService extends Service
if (\config('translation_service.enable', false)) {
$this->translateContent($category, $data->getContents());
}
$this->clearCacheCommandHandler->all();
} catch (ServiceException $e) {
return $e->getServiceResultError();
} catch (ParentException $e) {
@@ -255,6 +267,8 @@ final class DocumentationCategoryService extends Service
DB::transaction(function () use ($category) {
$this->categoryCommandHandler->handleDestroy($category);
});
$this->clearCacheCommandHandler->all();
} catch (\Throwable $e) {
report($e);
return $this->errService(__('Server Error'));