Fixed category display error from documentation. Previously, I showed all categories of documentation.
This commit is contained in:
parent
22bb840705
commit
a5e3c5ed25
@ -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(
|
||||
|
@ -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),
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -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'));
|
||||
|
Loading…
Reference in New Issue
Block a user