taktik - laravel
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Services\QueryRequestModifiers\Category;
|
||||
|
||||
use App\Http\Requests\Category\ListCategoryRequest;
|
||||
use App\Models\Category;
|
||||
use App\Services\QueryRequestModifiers\Filterable;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class CategoryFilter
|
||||
{
|
||||
/**
|
||||
* @use Filterable<Category, CategoryFilterDTO>
|
||||
*/
|
||||
use Filterable;
|
||||
|
||||
/**
|
||||
* @param Builder<Category> $query
|
||||
* @return Builder<Category>
|
||||
*/
|
||||
public function apply(Builder $query, ?CategoryFilterDTO $filters): Builder
|
||||
{
|
||||
return $this->applyFilterable($query, $filters);
|
||||
}
|
||||
|
||||
public function makeFromRequest(ListCategoryRequest $request): ?CategoryFilterDTO
|
||||
{
|
||||
return $this->makeFilterableFromRequest($request, CategoryFilterDTO::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, string>
|
||||
*/
|
||||
public function validateRules(): array
|
||||
{
|
||||
return [
|
||||
'name' => 'sometimes|string|max:255',
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return array<int, string>
|
||||
*/
|
||||
protected static function keys(): array
|
||||
{
|
||||
return ['name'];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Services\QueryRequestModifiers\Category;
|
||||
|
||||
use App\Services\CacheKeyInterface;
|
||||
|
||||
class CategoryFilterDTO implements CacheKeyInterface
|
||||
{
|
||||
/**
|
||||
* @param array<string, string> $filters
|
||||
*/
|
||||
public function __construct(public array $filters)
|
||||
{
|
||||
}
|
||||
|
||||
public function toCacheKey(): string
|
||||
{
|
||||
return http_build_query($this->filters, '', '|');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Services\QueryRequestModifiers\Category;
|
||||
|
||||
use App\Http\Requests\Category\ListCategoryRequest;
|
||||
use App\Models\Category;
|
||||
use App\Services\QueryRequestModifiers\Orderable;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class CategoryOrder
|
||||
{
|
||||
/**
|
||||
* @use Orderable<Category, CategoryOrderDTO>
|
||||
*/
|
||||
use Orderable;
|
||||
|
||||
|
||||
/**
|
||||
* @param Builder<Category> $query
|
||||
* @return Builder<Category>
|
||||
*/
|
||||
public function apply(Builder $query, ?CategoryOrderDTO $filters): Builder
|
||||
{
|
||||
return $this->applyOrderable($query, $filters);
|
||||
}
|
||||
|
||||
public function makeFromRequest(ListCategoryRequest $request): ?CategoryOrderDTO
|
||||
{
|
||||
return $this->makeOrderableFromRequest($request, CategoryOrderDTO::class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Services\QueryRequestModifiers\Category;
|
||||
|
||||
use App\Services\CacheKeyInterface;
|
||||
use App\Services\QueryRequestModifiers\OrderableDTO;
|
||||
use App\Services\QueryRequestModifiers\SortDirection;
|
||||
|
||||
/**
|
||||
* @implements OrderableDTO<CategoryOrderDTO>
|
||||
*/
|
||||
class CategoryOrderDTO implements CacheKeyInterface, OrderableDTO
|
||||
{
|
||||
public function __construct(public string $column, public SortDirection $direction)
|
||||
{
|
||||
}
|
||||
|
||||
public function toCacheKey(): string
|
||||
{
|
||||
return $this->column . '|' . $this->direction->value;
|
||||
}
|
||||
|
||||
public function getColumn(): string
|
||||
{
|
||||
return $this->column;
|
||||
}
|
||||
|
||||
public function getDirection(): SortDirection
|
||||
{
|
||||
return $this->direction;
|
||||
}
|
||||
|
||||
public static function createFromValues(string $column, SortDirection $sortDirection): OrderableDTO
|
||||
{
|
||||
return new self(
|
||||
$column,
|
||||
$sortDirection
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user