Implemented interaction with docker registry.
This commit is contained in:
61
app/application/app/Repositories/RepositoryRepository.php
Normal file
61
app/application/app/Repositories/RepositoryRepository.php
Normal file
@@ -0,0 +1,61 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace App\Repositories;
|
||||
|
||||
use App\Contracts\Search;
|
||||
use App\Models\Repository;
|
||||
use App\Models\User;
|
||||
use App\Dto\Builder\Repository as RepositoryBuilderDto;
|
||||
use App\Services\Repository\BuilderCommand;
|
||||
use App\Services\Search\CreateSearchInstanceCommand;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
final readonly class RepositoryRepository
|
||||
{
|
||||
public function __construct(
|
||||
private CreateSearchInstanceCommand $createSearchInstanceCommand,
|
||||
private BuilderCommand $builderCommand,
|
||||
) { }
|
||||
|
||||
public function getRepositoryByName(User $user, string $name, bool $withTrashed = false): ?Repository
|
||||
{
|
||||
$query = $user->repositories();
|
||||
if ($withTrashed) {
|
||||
$query->withTrashed();
|
||||
}
|
||||
|
||||
return $query->where('name', $name)->first();
|
||||
}
|
||||
|
||||
public function getRepositories(RepositoryBuilderDto $builderDto, array $with = []): Search
|
||||
{
|
||||
$query = $this->builderCommand->execute(
|
||||
query: Repository::query()->with($with)->orderByDesc('updated_at'),
|
||||
builderDto: $builderDto
|
||||
);
|
||||
|
||||
return $this->createSearchInstanceCommand->execute($query);
|
||||
}
|
||||
|
||||
public function getUserRepositories(User $user, RepositoryBuilderDto $builderDto, array $with = []): Search
|
||||
{
|
||||
$query = $this->builderCommand->execute(
|
||||
query: $user->repositories()->with($with)->orderByDesc('updated_at'),
|
||||
builderDto: $builderDto
|
||||
);
|
||||
|
||||
return $this->createSearchInstanceCommand->execute($query);
|
||||
}
|
||||
|
||||
public function isExistsName(User $user, string $name, ?int $exceptId = null): bool
|
||||
{
|
||||
return $user->repositories()
|
||||
->where('name', Str::lower($name))
|
||||
->when($exceptId, function (Builder $query, int $exceptId) {
|
||||
$query->where('id', '!=', $exceptId);
|
||||
})
|
||||
->withTrashed()
|
||||
->exists();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user