fix: do the validation via JsonMapper instead
This commit is contained in:
parent
b363bf9fc2
commit
0bfdfc9b4e
|
@ -1,29 +1,17 @@
|
|||
<?php
|
||||
|
||||
namespace App\Facade\Filters;
|
||||
|
||||
use App\Facade\Filters\Pagination;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Validation\Rule;
|
||||
use Illuminate\Http\Exceptions\HttpResponseException;
|
||||
|
||||
use Error;
|
||||
use JsonMapper;
|
||||
|
||||
class Filters
|
||||
{
|
||||
|
||||
public static function rules()
|
||||
{
|
||||
return [
|
||||
'filters.*.column' => [ 'required', 'string' ],
|
||||
'filters.*.type' => [ 'required', Rule::enum(FilterTypeEnum::class) ],
|
||||
'filters.*.filter' => [ 'required', 'nullable', 'string' ],
|
||||
|
||||
'orders.*.by' => [ 'required', 'string' ],
|
||||
'orders.*.sort' => [ 'required', Rule::enum(OrderTypeEnum::class) ],
|
||||
|
||||
'pagination.size' => 'number',
|
||||
'pagination.page' => 'number',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @var Filter[]
|
||||
*/
|
||||
|
@ -47,7 +35,11 @@ class Filters
|
|||
$data->orders ??= [];
|
||||
$data->pagination ??= null;
|
||||
|
||||
return $mapper->map($data, \App\Facade\Filters\Filters::class);
|
||||
try {
|
||||
return $mapper->map($data, \App\Facade\Filters\Filters::class);
|
||||
} catch (Error $err) {
|
||||
throw new HttpResponseException(response()->json([ 'unknown' => $err->getMessage() ], 422));
|
||||
}
|
||||
}
|
||||
|
||||
public function apply(Builder $builder)
|
||||
|
|
|
@ -1,12 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
use App\Facade\Filters\Filters;
|
||||
|
||||
class AuthorizedFilterListRequest extends AuthorizedRequest
|
||||
{
|
||||
public function rules()
|
||||
{
|
||||
return Filters::rules();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue