Added the ability to manage a group of users.

This commit is contained in:
2023-07-16 19:21:09 +06:00
parent ba7e52f8ac
commit 4083e2ec5e
45 changed files with 1173 additions and 10 deletions

View File

@@ -2,12 +2,48 @@
namespace App\Repositories;
use App\Contracts\Search;
use App\Models\Role;
use App\Dto\Builder\Role as RoleBuilderDto;
use App\Services\Role\BuilderCommand;
use App\Services\Search\CreateSearchInstanceCommand;
use Illuminate\Database\Eloquent\Builder;
final readonly class RoleRepository
{
public function getRoleBySlug(string $slug): ?Role
final public function __construct(
private CreateSearchInstanceCommand $createSearchInstanceCommand,
private BuilderCommand $builderCommand
) { }
public function getRoleById(int $id): ?Role
{
return Role::query()->where('slug', $slug)->first();
return Role::query()->where('id', $id)->first();
}
public function getRoleByCode(string $code): ?Role
{
return Role::query()->where('code', $code)->first();
}
public function getRoles(RoleBuilderDto $roleBuilderDto, array $with = []): Search
{
$query = $this->builderCommand->execute(
query: Role::query()->with($with),
roleBuilderDto: $roleBuilderDto
);
return $this->createSearchInstanceCommand->execute($query);
}
public function isExistsCode(string $code, ?int $exceptId = null): bool
{
return Role::query()
->where('code', $code)
->when($exceptId, function (Builder $query, int $exceptId) {
$query->where('id', '!=', $exceptId);
})
->withTrashed()
->exists();
}
}