Add captcha tokens management.
This commit is contained in:
39
app/Repositories/CaptchaTokenRepository.php
Normal file
39
app/Repositories/CaptchaTokenRepository.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace App\Repositories;
|
||||
|
||||
use App\Contracts\Search;
|
||||
use App\Models\CaptchaToken;
|
||||
use App\Services\CaptchaToken\BuilderCommand;
|
||||
use App\Services\Search\CreateSearchInstanceCommand;
|
||||
use App\Dto\Builder\CaptchaToken as CaptchaTokenDto;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
final readonly class CaptchaTokenRepository
|
||||
{
|
||||
public function __construct(
|
||||
private CreateSearchInstanceCommand $createSearchInstanceCommand,
|
||||
private BuilderCommand $builderCommand
|
||||
) { }
|
||||
|
||||
public function getCaptchaTokenById(int $id): ?CaptchaToken
|
||||
{
|
||||
return CaptchaToken::query()->where('id', $id)->first();
|
||||
}
|
||||
|
||||
public function getCaptchaTokens(CaptchaTokenDto $captchaTokenDto, array $with = [], ?int $userId = null): Search
|
||||
{
|
||||
$query = CaptchaToken::query()
|
||||
->when($userId, function (Builder $query, int $userId) {
|
||||
$query->where('user_id', $userId);
|
||||
})
|
||||
->with($with);
|
||||
|
||||
$query = $this->builderCommand->execute(
|
||||
query: $query,
|
||||
captchaTokenDto: $captchaTokenDto
|
||||
);
|
||||
|
||||
return $this->createSearchInstanceCommand->execute($query);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user