Add category-specific documentation view and management

- Introduce routes and controller actions for displaying and managing documentation by category.
- Adjust views to incorporate category-specific information and actions.
- Update services to handle category retrieval and validation.
- Add localized strings for new functionality in English and Russian.
This commit is contained in:
2026-07-22 01:01:53 +05:00
parent 756cafdbff
commit d3a84bad04
9 changed files with 226 additions and 33 deletions
@@ -2,12 +2,17 @@
namespace App\Services\Admin\Project;
use App\Dto\Builder\Documentation as DocumentationBuilderDto;
use App\Dto\Builder\DocumentationCategory as DocumentationCategoryBuilderDto;
use App\Dto\QuerySettingsDto;
use App\Dto\Builder\DocumentationVersion as DocumentationVersionBuilderDto;
use App\Dto\Service\Admin\Project\DocumentationVersion\StoreUpdate;
use App\Enums\DocumentationVersionStatus;
use App\Models\DocumentationVersion;
use App\Models\ProjectLanguage;
use App\Models\User;
use App\Repositories\DocumentationCategoryRepository;
use App\Repositories\DocumentationRepository;
use App\Repositories\DocumentationVersionRepository;
use App\Repositories\ProjectRepository;
use App\ServiceResults\ServiceResultArray;
@@ -17,6 +22,8 @@ use App\ServiceResults\StoreUpdateResult;
use App\Services\ClearCacheCommandHandler;
use App\Services\DocumentationVersion\DocumentationVersionCommandHandler;
use App\Services\Service;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Relations\HasOne;
use Illuminate\Support\Facades\DB;
final class DocumentationVersionService extends Service
@@ -26,6 +33,9 @@ final class DocumentationVersionService extends Service
private readonly DocumentationVersionRepository $documentationVersionRepository,
private readonly DocumentationVersionCommandHandler $documentationVersionCommandHandler,
private readonly ClearCacheCommandHandler $clearCacheCommandHandler,
private readonly DocumentationCategoryRepository $documentationCategoryRepository,
private readonly DocumentationRepository $documentationRepository
) { }
public function index(int $projectId, DocumentationVersionBuilderDto $documentationVersionBuilderDto, QuerySettingsDto $querySettingsDto, User $user): ServiceResultError | ServiceResultArray
@@ -54,7 +64,7 @@ final class DocumentationVersionService extends Service
]);
}
public function show(int $projectId, int $versionId, User $user): ServiceResultError | ServiceResultArray
public function show(int $projectId, int $versionId, ?int $categoryId, User $user): ServiceResultError | ServiceResultArray
{
$project = $this->projectRepository->getProjectById($projectId);
if (\is_null($project)) {
@@ -70,9 +80,48 @@ final class DocumentationVersionService extends Service
return $this->errFobidden(__('Access is denied'));
}
$category = null;
if (!\is_null($categoryId)) {
$category = $this->documentationCategoryRepository->getCategoryById($categoryId);
if (\is_null($category) || $category->version_id !== $version->id) {
return $this->errNotFound(__('Not Found'));
}
if ($user->cannot('view', $category)) {
return $this->errFobidden(__('Access is denied'));
}
}
$defaultLanguage = $project->languages()->where('is_default', 1)->first();
$with = [
'content' => function (HasOne $hasOne) use ($defaultLanguage) {
/** @var ?ProjectLanguage $defaultLanguage */
$hasOne->when($defaultLanguage, function (Builder $query, ProjectLanguage $defaultLanguage) {
$query->where('language_id', $defaultLanguage->id);
});
}
];
$categoryDto = new DocumentationCategoryBuilderDto\Category($category->id ?? null);
$categories = $this->documentationCategoryRepository
->getCategories(
$version->id,
new DocumentationCategoryBuilderDto(parentId: $categoryDto),
$with
)->all();
$documents = $this->documentationRepository
->getDocumentations(
$version->id,
new DocumentationBuilderDto(categoryId: $categoryDto),
$with
)->all();
return $this->result([
'version' => $version,
'project' => $project,
'category' => $category,
'categories' => $categories,
'documentations' => $documents,
]);
}