A documentation section has been added to the admin panel.
This commit is contained in:
51
app/application/app/Repositories/DocumentationRepository.php
Normal file
51
app/application/app/Repositories/DocumentationRepository.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace App\Repositories;
|
||||
|
||||
use App\Dto\Builder\Documentation as DocumentationBuilderDto;
|
||||
use App\Contracts\Search;
|
||||
use App\Models\Documentation;
|
||||
use App\Services\Documentation\BuilderCommand;
|
||||
use App\Services\Search\CreateSearchInstanceCommand;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
final readonly class DocumentationRepository
|
||||
{
|
||||
public function __construct(
|
||||
private CreateSearchInstanceCommand $createSearchInstanceCommand,
|
||||
private BuilderCommand $builderCommand
|
||||
) { }
|
||||
|
||||
public function getDocumentations(int $versionId, DocumentationBuilderDto $documentationBuilderDto, array $with = []): Search
|
||||
{
|
||||
$query = $this->builderCommand->execute(
|
||||
query: Documentation::query()->where('version_id', $versionId)->with($with),
|
||||
documentationBuilderDto: $documentationBuilderDto
|
||||
);
|
||||
|
||||
return $this->createSearchInstanceCommand->execute($query);
|
||||
}
|
||||
|
||||
public function getDocumentationById(int $id): ?Documentation
|
||||
{
|
||||
return Documentation::query()->where('id', $id)->first();
|
||||
}
|
||||
|
||||
public function getDocumentationByCode(string $code): ?Documentation
|
||||
{
|
||||
return Documentation::query()->where('code', $code)->first();
|
||||
}
|
||||
|
||||
public function isExistsSlug(int $versionId, string $slug, ?int $exceptId = null): bool
|
||||
{
|
||||
return Documentation::query()
|
||||
->where('version_id', $versionId)
|
||||
->where('slug', Str::lower($slug))
|
||||
->when($exceptId, function (Builder $query, int $exceptId) {
|
||||
$query->where('id', '!=', $exceptId);
|
||||
})
|
||||
->withTrashed()
|
||||
->exists();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user