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:
@@ -20,6 +20,7 @@ use App\ServiceResults\ServiceResultArray;
|
|||||||
use App\ServiceResults\ServiceResultError;
|
use App\ServiceResults\ServiceResultError;
|
||||||
use App\ServiceResults\ServiceResultSuccess;
|
use App\ServiceResults\ServiceResultSuccess;
|
||||||
use App\ServiceResults\StoreUpdateResult;
|
use App\ServiceResults\StoreUpdateResult;
|
||||||
|
use App\Services\ClearCacheCommandHandler;
|
||||||
use App\Services\DocumentationCategory\DocumentationCategoryCommandHandler;
|
use App\Services\DocumentationCategory\DocumentationCategoryCommandHandler;
|
||||||
use App\Services\DocumentationCategoryContent\ModelSyncCommand;
|
use App\Services\DocumentationCategoryContent\ModelSyncCommand;
|
||||||
use App\Services\Service;
|
use App\Services\Service;
|
||||||
@@ -34,6 +35,7 @@ final class DocumentationCategoryService extends Service
|
|||||||
private readonly DocumentationCategoryRepository $documentationCategoryRepository,
|
private readonly DocumentationCategoryRepository $documentationCategoryRepository,
|
||||||
private readonly DocumentationCategoryCommandHandler $categoryCommandHandler,
|
private readonly DocumentationCategoryCommandHandler $categoryCommandHandler,
|
||||||
private readonly ModelSyncCommand $contentSaveCommand,
|
private readonly ModelSyncCommand $contentSaveCommand,
|
||||||
|
private readonly ClearCacheCommandHandler $clearCacheCommandHandler,
|
||||||
) { }
|
) { }
|
||||||
|
|
||||||
public function index(int $projectId, int $versionId, DocumentationCategoryBuilderDto $documentationCategoryBuilderDto, QuerySettingsDto $querySettingsDto, User $user): ServiceResultError | ServiceResultArray
|
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();
|
$defaultLanguage = $project->languages->where('is_default', 1)->first();
|
||||||
$category = new DocumentationCategory();
|
$category = new DocumentationCategory();
|
||||||
|
$categoryPath = null;
|
||||||
if ($parentId !== null) {
|
if ($parentId !== null) {
|
||||||
$category->parent_id = $parentId;
|
$category->parent_id = $parentId;
|
||||||
|
$categoryPath = $this->documentationCategoryRepository->getPathFromRoot($parentId, $defaultLanguage);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->result([
|
return $this->result([
|
||||||
@@ -99,6 +103,7 @@ final class DocumentationCategoryService extends Service
|
|||||||
'category' => $category,
|
'category' => $category,
|
||||||
'categories' => $this->documentationCategoryRepository->getForSelect($version, $defaultLanguage),
|
'categories' => $this->documentationCategoryRepository->getForSelect($version, $defaultLanguage),
|
||||||
'serviceTranslationEnable' => config('translation_service.enable', false),
|
'serviceTranslationEnable' => config('translation_service.enable', false),
|
||||||
|
'categoryPath' => $categoryPath,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -119,17 +124,20 @@ final class DocumentationCategoryService extends Service
|
|||||||
return $this->errFobidden(__('Access is denied'));
|
return $this->errFobidden(__('Access is denied'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$defaultLanguage = $project->languages->where('is_default', 1)->first();
|
||||||
$withCategories = [];
|
$withCategories = [];
|
||||||
|
$categoryPath = null;
|
||||||
if ($category->parent_id) {
|
if ($category->parent_id) {
|
||||||
$withCategories[] = $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([
|
return $this->result([
|
||||||
'version' => $version,
|
'version' => $version,
|
||||||
'project' => $project,
|
'project' => $project,
|
||||||
'category' => $category,
|
'category' => $category,
|
||||||
'categories' => $this->documentationCategoryRepository->getForSelect($version, $defaultLanguage, $category, $withCategories),
|
'categories' => $this->documentationCategoryRepository->getForSelect($version, $defaultLanguage, $category, $withCategories),
|
||||||
'serviceTranslationEnable' => config('translation_service.enable', false),
|
'serviceTranslationEnable' => config('translation_service.enable', false),
|
||||||
|
'categoryPath' => $categoryPath,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -165,6 +173,8 @@ final class DocumentationCategoryService extends Service
|
|||||||
if (\config('translation_service.enable', false)) {
|
if (\config('translation_service.enable', false)) {
|
||||||
$this->translateContent($category, $data->getContents());
|
$this->translateContent($category, $data->getContents());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->clearCacheCommandHandler->all();
|
||||||
} catch (ServiceException $e) {
|
} catch (ServiceException $e) {
|
||||||
return $e->getServiceResultError();
|
return $e->getServiceResultError();
|
||||||
} catch (\Throwable $e) {
|
} catch (\Throwable $e) {
|
||||||
@@ -219,6 +229,8 @@ final class DocumentationCategoryService extends Service
|
|||||||
if (\config('translation_service.enable', false)) {
|
if (\config('translation_service.enable', false)) {
|
||||||
$this->translateContent($category, $data->getContents());
|
$this->translateContent($category, $data->getContents());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->clearCacheCommandHandler->all();
|
||||||
} catch (ServiceException $e) {
|
} catch (ServiceException $e) {
|
||||||
return $e->getServiceResultError();
|
return $e->getServiceResultError();
|
||||||
} catch (ParentException $e) {
|
} catch (ParentException $e) {
|
||||||
@@ -255,6 +267,8 @@ final class DocumentationCategoryService extends Service
|
|||||||
DB::transaction(function () use ($category) {
|
DB::transaction(function () use ($category) {
|
||||||
$this->categoryCommandHandler->handleDestroy($category);
|
$this->categoryCommandHandler->handleDestroy($category);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$this->clearCacheCommandHandler->all();
|
||||||
} catch (\Throwable $e) {
|
} catch (\Throwable $e) {
|
||||||
report($e);
|
report($e);
|
||||||
return $this->errService(__('Server Error'));
|
return $this->errService(__('Server Error'));
|
||||||
|
|||||||
Reference in New Issue
Block a user