2023-08-22 00:15:35 +06:00
|
|
|
<?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);
|
|
|
|
}
|
2023-09-19 14:27:33 +06:00
|
|
|
|
|
|
|
public function getCaptchaTokenByPublicToken(string $token): ?CaptchaToken
|
|
|
|
{
|
|
|
|
return CaptchaToken::query()->where('public_token', '=', $token)->first();
|
|
|
|
}
|
2023-11-26 22:42:22 +06:00
|
|
|
|
|
|
|
public function getCaptchaTokenByPrivateToken(string $token): ?CaptchaToken
|
|
|
|
{
|
|
|
|
return CaptchaToken::query()->where('private_token', '=', $token)->first();
|
|
|
|
}
|
2023-08-22 00:15:35 +06:00
|
|
|
}
|