From a5e3c5ed2591cfb061a6cdbdb204b17074af92a7 Mon Sep 17 00:00:00 2001 From: Leonid Nikitin Date: Fri, 26 Jul 2024 22:11:54 +0500 Subject: [PATCH] Fixed category display error from documentation. Previously, I showed all categories of documentation. --- .../Repositories/DocumentationCategoryRepository.php | 5 ++--- .../Admin/Project/DocumentationCategoryService.php | 4 ++-- .../Services/Admin/Project/DocumentationService.php | 10 +++++++--- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/app/application/app/Repositories/DocumentationCategoryRepository.php b/app/application/app/Repositories/DocumentationCategoryRepository.php index 81e2d65..1f013aa 100644 --- a/app/application/app/Repositories/DocumentationCategoryRepository.php +++ b/app/application/app/Repositories/DocumentationCategoryRepository.php @@ -11,7 +11,6 @@ use App\Dto\Builder\DocumentationCategory as DocumentationCategoryBuilderDto; use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Relations\HasOne; -use Illuminate\Support\Collection; use Illuminate\Support\Str; final readonly class DocumentationCategoryRepository @@ -63,7 +62,7 @@ public function isExistsSlug(int $versionId, string $slug, ?int $exceptId = null ->exists(); } - public function getForSelect(?ProjectLanguage $defaultLanguage, ?DocumentationCategory $exceptCategory = null, array $withExcepts = []): array + public function getForSelect(DocumentationVersion $version, ?ProjectLanguage $defaultLanguage, ?DocumentationCategory $exceptCategory = null, array $withExcepts = []): array { $with = [ 'content' => function (HasOne $hasOne) use ($defaultLanguage) { @@ -73,7 +72,7 @@ public function getForSelect(?ProjectLanguage $defaultLanguage, ?DocumentationCa } ]; - $categories = DocumentationCategory::query() + $categories = $version->categories() ->with($with) ->when($exceptCategory, function (Builder $query, DocumentationCategory $exceptCategory) { $query->whereNotIn( diff --git a/app/application/app/Services/Admin/Project/DocumentationCategoryService.php b/app/application/app/Services/Admin/Project/DocumentationCategoryService.php index f64ba24..b1390b6 100644 --- a/app/application/app/Services/Admin/Project/DocumentationCategoryService.php +++ b/app/application/app/Services/Admin/Project/DocumentationCategoryService.php @@ -89,7 +89,7 @@ public function create(int $projectId, int $versionId, User $user): ServiceResul 'version' => $version, 'project' => $project, 'category' => new DocumentationCategory(), - 'categories' => $this->documentationCategoryRepository->getForSelect($defaultLanguage), + 'categories' => $this->documentationCategoryRepository->getForSelect($version, $defaultLanguage), ]); } @@ -119,7 +119,7 @@ public function edit(int $projectId, int $versionId, int $categoryId, User $user 'version' => $version, 'project' => $project, 'category' => $category, - 'categories' => $this->documentationCategoryRepository->getForSelect($defaultLanguage, $category, $withCategories), + 'categories' => $this->documentationCategoryRepository->getForSelect($version, $defaultLanguage, $category, $withCategories), ]); } diff --git a/app/application/app/Services/Admin/Project/DocumentationService.php b/app/application/app/Services/Admin/Project/DocumentationService.php index 8317486..26e1693 100644 --- a/app/application/app/Services/Admin/Project/DocumentationService.php +++ b/app/application/app/Services/Admin/Project/DocumentationService.php @@ -5,13 +5,13 @@ use App\Dto\Builder\Documentation as DocumentationBuilderDto; use App\Dto\QuerySettingsDto; use App\Dto\Service\Admin\Project\Documentation\StoreUpdate; +use App\Exceptions\Services\DocumentationContent\StorageCommandException; use App\Models\Documentation; 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; use App\ServiceResults\ServiceResultError; use App\ServiceResults\ServiceResultSuccess; @@ -89,7 +89,7 @@ public function create(int $projectId, int $versionId, User $user): ServiceResul 'version' => $version, 'project' => $project, 'documentation' => new Documentation(), - 'categories' => $this->documentationCategoryRepository->getForSelect($defaultLanguage), + 'categories' => $this->documentationCategoryRepository->getForSelect($version, $defaultLanguage), ]); } @@ -119,7 +119,7 @@ public function edit(int $projectId, int $versionId, int $documentationId, User 'version' => $version, 'project' => $project, 'documentation' => $documentation, - 'categories' => $this->documentationCategoryRepository->getForSelect($defaultLanguage, null, $withCategories), + 'categories' => $this->documentationCategoryRepository->getForSelect($version, $defaultLanguage, null, $withCategories), ]); } @@ -150,6 +150,8 @@ public function store(int $projectId, int $versionId, StoreUpdate $data, User $u return $documentation; }); + } catch (StorageCommandException $e) { + return $e->getResultError(); } catch (\Throwable $e) { report($e); return $this->errService(__('Server Error')); @@ -190,6 +192,8 @@ public function update(int $projectId, int $versionId, int $documentationId, Sto return $documentation; }); + } catch (StorageCommandException $e) { + return $e->getResultError(); } catch (\Throwable $e) { report($e); return $this->errService(__('Server Error'));