78 lines
1.8 KiB
PHP
78 lines
1.8 KiB
PHP
|
<?php
|
||
|
|
||
|
declare(strict_types=1);
|
||
|
|
||
|
namespace App\Http\Requests\Comment;
|
||
|
|
||
|
use App\Http\Requests\InvalidDataResponseTrait;
|
||
|
use App\Services\QueryRequestModifiers\Comment\CommentFilter;
|
||
|
use App\Services\QueryRequestModifiers\Comment\CommentFilterDTO;
|
||
|
use App\Services\QueryRequestModifiers\Comment\CommentOrder;
|
||
|
use App\Services\QueryRequestModifiers\Comment\CommentOrderDTO;
|
||
|
use Illuminate\Foundation\Http\FormRequest;
|
||
|
|
||
|
class ListCommentRequest extends FormRequest
|
||
|
{
|
||
|
use InvalidDataResponseTrait;
|
||
|
|
||
|
public function __construct(
|
||
|
private readonly CommentOrder $commentOrder,
|
||
|
private readonly CommentFilter $commentFilter,
|
||
|
) {
|
||
|
}
|
||
|
|
||
|
|
||
|
/**
|
||
|
* @return array<string, string>
|
||
|
*/
|
||
|
public function all($keys = null): array
|
||
|
{
|
||
|
$request = parent::all($keys);
|
||
|
|
||
|
$request['page'] = $this->route('page');
|
||
|
$request['post_id'] = $this->route('post_id');
|
||
|
|
||
|
return $request;
|
||
|
}
|
||
|
|
||
|
public function authorize(): bool
|
||
|
{
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @return array<string, string>
|
||
|
*/
|
||
|
public function rules(): array
|
||
|
{
|
||
|
return [
|
||
|
'page' => 'required|integer|min:1',
|
||
|
'post_id' => 'required|integer|min:0',
|
||
|
... $this->commentFilter->validateRules(),
|
||
|
... $this->commentOrder->validateRules()
|
||
|
];
|
||
|
}
|
||
|
|
||
|
|
||
|
/**
|
||
|
* @return array<string, string>
|
||
|
*/
|
||
|
public function attributes(): array
|
||
|
{
|
||
|
return [
|
||
|
'page' => 'page number',
|
||
|
'post_id' => 'post id',
|
||
|
];
|
||
|
}
|
||
|
|
||
|
public function filters(): ?CommentFilterDTO
|
||
|
{
|
||
|
return $this->commentFilter->makeFromRequest($this);
|
||
|
}
|
||
|
|
||
|
public function order(): ?CommentOrderDTO
|
||
|
{
|
||
|
return $this->commentOrder->makeFromRequest($this);
|
||
|
}
|
||
|
}
|