diff --git a/config/app.neon b/config/app.neon index 56c1c02..693ddc2 100644 --- a/config/app.neon +++ b/config/app.neon @@ -23,6 +23,7 @@ services: - Megio\Collection\RecipeFinder - Megio\Collection\ReadBuilder\ReadBuilder - Megio\Collection\WriteBuilder\WriteBuilder + - Megio\Collection\SearchBuilder\SearchBuilder - Megio\Security\JWT\JWTResolver - Megio\Security\JWT\ClaimsFormatter diff --git a/src/Collection/CollectionRecipe.php b/src/Collection/CollectionRecipe.php index b982dc6..ddcc100 100644 --- a/src/Collection/CollectionRecipe.php +++ b/src/Collection/CollectionRecipe.php @@ -5,32 +5,38 @@ use Doctrine\ORM\Mapping\Table; use Megio\Collection\Exception\CollectionException; +use Megio\Collection\SearchBuilder\SearchBuilder; use Megio\Collection\WriteBuilder\WriteBuilder; use Megio\Collection\ReadBuilder\ReadBuilder; use Megio\Database\Interface\ICrudable; abstract class CollectionRecipe implements ICollectionRecipe { - public function read(ReadBuilder $builder, RecipeRequest $request): ReadBuilder + public function read(ReadBuilder $builder, CollectionRequest $request): ReadBuilder { return $builder->buildByDbSchema(); } - public function readAll(ReadBuilder $builder, RecipeRequest $request): ReadBuilder + public function readAll(ReadBuilder $builder, CollectionRequest $request): ReadBuilder { return $builder->buildByDbSchema(); } - public function create(WriteBuilder $builder, RecipeRequest $request): WriteBuilder + public function create(WriteBuilder $builder, CollectionRequest $request): WriteBuilder { return $builder->buildByDbSchema(); } - public function update(WriteBuilder $builder, RecipeRequest $request): WriteBuilder + public function update(WriteBuilder $builder, CollectionRequest $request): WriteBuilder { return $builder->buildByDbSchema(); } + public function search(SearchBuilder $builder, CollectionRequest $request): SearchBuilder + { + return $builder->keepDefaults(); + } + /** * @throws \Megio\Collection\Exception\CollectionException */ diff --git a/src/Collection/RecipeRequest.php b/src/Collection/CollectionRequest.php similarity index 58% rename from src/Collection/RecipeRequest.php rename to src/Collection/CollectionRequest.php index ea590e5..26b4b84 100644 --- a/src/Collection/RecipeRequest.php +++ b/src/Collection/CollectionRequest.php @@ -3,24 +3,23 @@ namespace Megio\Collection; -use Megio\Collection\WriteBuilder\Field\Base\UndefinedValue; use Symfony\Component\HttpFoundation\Request; -class RecipeRequest +class CollectionRequest { /** * @param \Symfony\Component\HttpFoundation\Request $request * @param bool $isFormRendering + * @param array $requestData * @param string|null $rowId * @param array $rowValues - * @param mixed|UndefinedValue $customData */ public function __construct( protected Request &$request, protected bool $isFormRendering, + protected mixed $requestData, protected ?string $rowId = null, protected array $rowValues = [], - protected mixed $customData = new UndefinedValue(), ) { } @@ -45,8 +44,29 @@ public function getRowValues(): mixed return $this->rowValues; } + /** + * @return array + */ + public function getRequestData(): mixed + { + return $this->requestData; + } + public function getCustomData(): mixed { - return $this->customData; + if (array_key_exists('custom_data', $this->requestData)) { + return $this->requestData['custom_data']; + } + + return []; + } + + public function getSearchText(): ?string + { + if (array_key_exists('search', $this->requestData) && array_key_exists('text', $this->requestData['search'])) { + return $this->requestData['search']['text']; + } + + return null; } } \ No newline at end of file diff --git a/src/Collection/ICollectionRecipe.php b/src/Collection/ICollectionRecipe.php index ea3faaf..438430f 100644 --- a/src/Collection/ICollectionRecipe.php +++ b/src/Collection/ICollectionRecipe.php @@ -3,9 +3,9 @@ namespace Megio\Collection; +use Megio\Collection\SearchBuilder\SearchBuilder; use Megio\Collection\WriteBuilder\WriteBuilder; use Megio\Collection\ReadBuilder\ReadBuilder; -use Symfony\Component\HttpFoundation\Request; interface ICollectionRecipe { @@ -16,14 +16,16 @@ public function source(): string; public function key(): string; /** @throws \Megio\Collection\Exception\CollectionException */ - public function read(ReadBuilder $builder, RecipeRequest $request): ReadBuilder; + public function read(ReadBuilder $builder, CollectionRequest $request): ReadBuilder; /** @throws \Megio\Collection\Exception\CollectionException */ - public function readAll(ReadBuilder $builder, RecipeRequest $request): ReadBuilder; + public function readAll(ReadBuilder $builder, CollectionRequest $request): ReadBuilder; - public function create(WriteBuilder $builder, RecipeRequest $request): WriteBuilder; + public function create(WriteBuilder $builder, CollectionRequest $request): WriteBuilder; - public function update(WriteBuilder $builder, RecipeRequest $request): WriteBuilder; + public function update(WriteBuilder $builder, CollectionRequest $request): WriteBuilder; + + public function search(SearchBuilder $builder, CollectionRequest $request): SearchBuilder; /** @throws \Megio\Collection\Exception\CollectionException */ public function getEntityMetadata(): RecipeEntityMetadata; diff --git a/src/Collection/SearchBuilder/SearchBuilder.php b/src/Collection/SearchBuilder/SearchBuilder.php new file mode 100644 index 0000000..f0f2691 --- /dev/null +++ b/src/Collection/SearchBuilder/SearchBuilder.php @@ -0,0 +1,106 @@ + */ + protected array $searchables = []; + + public function create(QueryBuilder $qb, CollectionRequest $request): self + { + $this->queryBuilder = $qb; + $this->request = $request; + + return $this; + } + + public function build(): QueryBuilder + { + // Text search + $searchText = $this->request->getSearchText(); + + if ($searchText !== null) { + $whereDql = []; + + foreach ($this->searchables as $searchable) { + $relationCol = $searchable->getRelation(); + $colName = 'entity.' . $searchable->getColumn(); + + if ($relationCol !== null) { + $alias = 'alias_' . $searchable->getRelation() . '_' . $searchable->getColumn(); + $this->queryBuilder->leftJoin("entity.{$relationCol}", $alias); + $colName = "{$alias}.{$searchable->getColumn()}"; + } + + $paramName = 'param_' . str_replace('.', '_', $colName); + $value = $searchable->hasFormatter() ? $searchable->format($searchText) : "%{$searchText}%"; + + $whereDql[] = [ + 'dql' => "{$colName} {$searchable->getOperator()} :{$paramName}", + 'paramName' => $paramName, + 'paramValue' => $value + ]; + } + + if (count($whereDql) !== 0) { + $where = implode(' OR ', array_map(fn($where) => $where['dql'], $whereDql)); + $this->queryBuilder->andWhere($where); + + foreach ($whereDql as $where) { + $this->queryBuilder->setParameter($where['paramName'], $where['paramValue']); + } + } + } + + return $this->queryBuilder; + } + + /** + * @param string[] $searchables + */ + public function keepDefaults(array $searchables = ['id', 'createdAt', 'updatedAt']): self + { + foreach ($searchables as $columnName) { + $this->addSearchable(new Searchable($columnName)); + } + + return $this; + } + + public function addSearchable(Searchable $searchable): self + { + $this->searchables[$searchable->getColumn()] = $searchable; + return $this; + } + + public function getQueryBuilder(): QueryBuilder + { + return $this->queryBuilder; + } + + public function getRequest(): CollectionRequest + { + return $this->request; + } + + /** @return array{ + * searchables: array{column: string, relation: string|null, operator: string}[] + * } + */ + public function toArray(): array + { + $searchables = array_map(fn(Searchable $searchable) => $searchable->toArray(), $this->searchables); + + return [ + 'searchables' => array_values($searchables), + ]; + } +} \ No newline at end of file diff --git a/src/Collection/SearchBuilder/Searchable.php b/src/Collection/SearchBuilder/Searchable.php new file mode 100644 index 0000000..4bd2d17 --- /dev/null +++ b/src/Collection/SearchBuilder/Searchable.php @@ -0,0 +1,59 @@ + */ + private array $formatter = []; + + public function __construct( + protected string $column, + protected ?string $relation = null, + protected string $operator = 'LIKE', + ?callable $formatter = null + ) + { + if ($formatter !== null) { + $this->formatter[] = $formatter; + } + } + + public function getColumn(): string + { + return $this->column; + } + + public function getRelation(): ?string + { + return $this->relation; + } + + public function getOperator(): string + { + return $this->operator; + } + + public function format(?string $value): mixed + { + return $this->formatter[0]($value); + } + + public function hasFormatter(): bool + { + return count($this->formatter) !== 0; + } + + /** + * @return array{column: string, relation: string|null, operator: string} + */ + public function toArray(): array + { + return [ + 'column' => $this->column, + 'relation' => $this->relation, + 'operator' => $this->operator, + ]; + } +} \ No newline at end of file diff --git a/src/Event/Collection/OnFormStartEvent.php b/src/Event/Collection/OnFormStartEvent.php index ff2ffca..584e5a9 100644 --- a/src/Event/Collection/OnFormStartEvent.php +++ b/src/Event/Collection/OnFormStartEvent.php @@ -4,7 +4,6 @@ namespace Megio\Event\Collection; use Megio\Collection\ICollectionRecipe; -use Megio\Collection\RecipeRequest; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Contracts\EventDispatcher\Event; diff --git a/src/Http/Request/Collection/CreateRequest.php b/src/Http/Request/Collection/CreateRequest.php index f42f10e..3e1841d 100644 --- a/src/Http/Request/Collection/CreateRequest.php +++ b/src/Http/Request/Collection/CreateRequest.php @@ -4,8 +4,8 @@ namespace Megio\Http\Request\Collection; use Doctrine\DBAL\Exception\ConstraintViolationException; +use Megio\Collection\CollectionRequest; use Megio\Collection\Exception\SerializerException; -use Megio\Collection\RecipeRequest; use Megio\Collection\WriteBuilder\WriteBuilder; use Megio\Collection\WriteBuilder\WriteBuilderEvent; use Megio\Collection\Exception\CollectionException; @@ -67,10 +67,10 @@ public function process(array $data): Response $ids = []; foreach ($data['rows'] as $row) { - $recipeRequest = new RecipeRequest($this->request, false, null, $row, $data['custom_data']); + $collectionRequest = new CollectionRequest($this->request, false, $data, null, $row); try { - $builder = $recipe->create($this->builder->create($recipe, WriteBuilderEvent::CREATE, null, $row), $recipeRequest)->build(); + $builder = $recipe->create($this->builder->create($recipe, WriteBuilderEvent::CREATE, null, $row), $collectionRequest)->build(); } catch (CollectionException $e) { $response = $this->error([$e->getMessage()], 406); $event = new OnExceptionEvent(EventType::CREATE, $data, $recipe, $e, $this->request, $response); diff --git a/src/Http/Request/Collection/Form/CreatingFormRequest.php b/src/Http/Request/Collection/Form/CreatingFormRequest.php index 9b13b61..4a22d99 100644 --- a/src/Http/Request/Collection/Form/CreatingFormRequest.php +++ b/src/Http/Request/Collection/Form/CreatingFormRequest.php @@ -3,8 +3,8 @@ namespace Megio\Http\Request\Collection\Form; +use Megio\Collection\CollectionRequest; use Megio\Collection\Exception\CollectionException; -use Megio\Collection\RecipeRequest; use Megio\Collection\WriteBuilder\WriteBuilder; use Megio\Collection\WriteBuilder\WriteBuilderEvent; use Megio\Collection\RecipeFinder; @@ -48,10 +48,10 @@ public function process(array $data): Response return $dispatcher->getResponse(); } - $recipeRequest = new RecipeRequest($this->request, true, null, [], $data['custom_data']); + $collectionRequest = new CollectionRequest($this->request, true, $data, null, []); try { - $builder = $recipe->create($this->builder->create($recipe, WriteBuilderEvent::CREATE), $recipeRequest)->build(); + $builder = $recipe->create($this->builder->create($recipe, WriteBuilderEvent::CREATE), $collectionRequest)->build(); } catch (CollectionException $e) { return $this->error([$e->getMessage()]); } diff --git a/src/Http/Request/Collection/Form/UpdatingFormRequest.php b/src/Http/Request/Collection/Form/UpdatingFormRequest.php index 46b8eca..fe5149c 100644 --- a/src/Http/Request/Collection/Form/UpdatingFormRequest.php +++ b/src/Http/Request/Collection/Form/UpdatingFormRequest.php @@ -4,10 +4,10 @@ namespace Megio\Http\Request\Collection\Form; use Doctrine\ORM\AbstractQuery; +use Megio\Collection\CollectionRequest; use Megio\Collection\Exception\CollectionException; use Megio\Collection\ReadBuilder\ReadBuilder; use Megio\Collection\ReadBuilder\ReadBuilderEvent; -use Megio\Collection\RecipeRequest; use Megio\Collection\WriteBuilder\WriteBuilder; use Megio\Collection\WriteBuilder\WriteBuilderEvent; use Megio\Collection\RecipeFinder; @@ -55,10 +55,10 @@ public function process(array $data): Response return $dispatcher->getResponse(); } - $recipeRequest = new RecipeRequest($this->request, true, null, [], $data['custom_data']); + $collectionRequest = new CollectionRequest($this->request, true, $data, null, []); try { - $readBuilder = $recipe->read($this->readBuilder->create($recipe, ReadBuilderEvent::READ_ONE), $recipeRequest)->build(); + $readBuilder = $recipe->read($this->readBuilder->create($recipe, ReadBuilderEvent::READ_ONE), $collectionRequest)->build(); $schema = $recipe->getEntityMetadata()->getFullSchemaReflectedByDoctrine(); $repo = $this->em->getRepository($recipe->source()); } catch (CollectionException $e) { @@ -85,7 +85,7 @@ public function process(array $data): Response $row[$column['name']] = $row[$column['name']]['id']; } } - + // Format one-to-many data foreach ($schema->getOneToManyColumns() as $column) { $row[$column['name']] = array_map(fn($item) => $item['id'], $row[$column['name']]); @@ -105,11 +105,11 @@ public function process(array $data): Response /** @var string $rowId */ $rowId = $row['id']; - $recipeRequest = new RecipeRequest($this->request, true, $rowId, $row, $data['custom_data']); + $collectionRequest = new CollectionRequest($this->request, true, $data, $rowId, $row); try { $builder = $recipe - ->update($this->writeBuilder->create($recipe, WriteBuilderEvent::UPDATE, $rowId, $row), $recipeRequest) + ->update($this->writeBuilder->create($recipe, WriteBuilderEvent::UPDATE, $rowId, $row), $collectionRequest) ->build(); } catch (CollectionException $e) { return $this->error([$e->getMessage()]); diff --git a/src/Http/Request/Collection/ReadAllRequest.php b/src/Http/Request/Collection/ReadAllRequest.php index efac56e..dae0196 100644 --- a/src/Http/Request/Collection/ReadAllRequest.php +++ b/src/Http/Request/Collection/ReadAllRequest.php @@ -5,13 +5,14 @@ use Doctrine\ORM\AbstractQuery; use Doctrine\ORM\Tools\Pagination\Paginator; +use Megio\Collection\CollectionRequest; use Megio\Collection\Exception\CollectionException; use Megio\Collection\ReadBuilder\Column\Base\IColumn; use Megio\Collection\ReadBuilder\ReadBuilder; use Megio\Collection\ReadBuilder\ReadBuilderEvent; use Megio\Collection\RecipeFinder; -use Megio\Collection\RecipeRequest; use Megio\Collection\SchemaFormatter; +use Megio\Collection\SearchBuilder\SearchBuilder; use Megio\Database\EntityManager; use Megio\Event\Collection\EventType; use Megio\Http\Request\Request; @@ -27,6 +28,7 @@ public function __construct( protected readonly EntityManager $em, protected readonly RecipeFinder $recipeFinder, protected readonly ReadBuilder $readBuilder, + protected readonly SearchBuilder $searchBuilder, ) { } @@ -42,6 +44,14 @@ public function schema(array $data): array 'adminPanel' => Expect::bool(false), 'currentPage' => Expect::int(1)->min(1)->required(), 'itemsPerPage' => Expect::int(10)->max(1000)->required(), + 'search' => Expect::structure([ + 'text' => Expect::string()->nullable()->default(null), + 'filters' => Expect::arrayOf(Expect::structure([ + 'col' => Expect::string()->required(), + 'operator' => Expect::anyOf('AND', 'OR')->required(), + 'value' => Expect::mixed()->required() + ])->castTo('array'))->min(0)->default([]), + ])->castTo('array'), 'orderBy' => Expect::arrayOf(Expect::structure([ 'col' => Expect::string()->required(), 'desc' => Expect::bool()->required() @@ -63,10 +73,10 @@ public function process(array $data): Response return $this->error(["Collection '{$data['recipe']}' not found"]); } - $recipeRequest = new RecipeRequest($this->request, false, null, [], $data['custom_data']); + $collectionRequest = new CollectionRequest($this->request, false, $data, null, []); try { - $builder = $recipe->readAll($this->readBuilder->create($recipe, ReadBuilderEvent::READ_ALL), $recipeRequest)->build(); + $builder = $recipe->readAll($this->readBuilder->create($recipe, ReadBuilderEvent::READ_ALL), $collectionRequest)->build(); } catch (CollectionException $e) { return $this->error([$e->getMessage()]); } @@ -85,16 +95,28 @@ public function process(array $data): Response $repo = $this->em->getRepository($recipe->source()); - $count = $repo->createQueryBuilder('entity') - ->select('count(entity.id)') - ->getQuery() - ->getSingleScalarResult(); + $countQb = $repo->createQueryBuilder('entity')->select('count(entity.id)'); + + // Search + if (array_key_exists('search', $data)) { + $sb = $this->searchBuilder->create($countQb, $collectionRequest); + $countQb = $recipe->search($sb, $sb->getRequest())->build(); + } + + // Count + $count = $countQb->getQuery()->getSingleScalarResult(); $qb = $builder ->createQueryBuilder($repo, 'entity') ->setFirstResult(($data['currentPage'] - 1) * $data['itemsPerPage']) ->setMaxResults($data['itemsPerPage']); + // Search + $sb = $this->searchBuilder->create($qb, $collectionRequest); + if (array_key_exists('search', $data)) { + $qb = $recipe->search($sb, $sb->getRequest())->build(); + } + // Sortable columns $sortable = array_filter($builder->getColumns(), fn(IColumn $col) => $col->isSortable()); $sortableKeys = array_map(fn(IColumn $col) => $col->getKey(), $sortable); @@ -128,9 +150,9 @@ public function process(array $data): Response 'items' => $items ]; - /** @noinspection DuplicatedCode */ if ($data['schema']) { $result['schema'] = SchemaFormatter::format($recipe, $builder); + $result['schema']['search'] = $sb->toArray(); } $response = $this->json($result); diff --git a/src/Http/Request/Collection/ReadRequest.php b/src/Http/Request/Collection/ReadRequest.php index 6454523..c3bd840 100644 --- a/src/Http/Request/Collection/ReadRequest.php +++ b/src/Http/Request/Collection/ReadRequest.php @@ -4,11 +4,11 @@ namespace Megio\Http\Request\Collection; use Doctrine\ORM\AbstractQuery; +use Megio\Collection\CollectionRequest; use Megio\Collection\Exception\CollectionException; use Megio\Collection\ReadBuilder\ReadBuilder; use Megio\Collection\ReadBuilder\ReadBuilderEvent; use Megio\Collection\RecipeFinder; -use Megio\Collection\RecipeRequest; use Megio\Collection\SchemaFormatter; use Megio\Event\Collection\EventType; use Megio\Http\Request\Request; @@ -56,10 +56,10 @@ public function process(array $data): Response return $this->error(["Collection '{$data['recipe']}' not found"]); } - $recipeRequest = new RecipeRequest($this->request, false, null, [], $data['custom_data']); + $collectionRequest = new CollectionRequest($this->request, false, $data, null, []); try { - $builder = $recipe->read($this->readBuilder->create($recipe, ReadBuilderEvent::READ_ONE), $recipeRequest)->build(); + $builder = $recipe->read($this->readBuilder->create($recipe, ReadBuilderEvent::READ_ONE), $collectionRequest)->build(); } catch (CollectionException $e) { return $this->error([$e->getMessage()]); } diff --git a/src/Http/Request/Collection/UpdateRequest.php b/src/Http/Request/Collection/UpdateRequest.php index 7720e3a..241aeaf 100644 --- a/src/Http/Request/Collection/UpdateRequest.php +++ b/src/Http/Request/Collection/UpdateRequest.php @@ -4,8 +4,8 @@ namespace Megio\Http\Request\Collection; use Doctrine\DBAL\Exception\ConstraintViolationException; +use Megio\Collection\CollectionRequest; use Megio\Collection\Exception\SerializerException; -use Megio\Collection\RecipeRequest; use Megio\Collection\WriteBuilder\WriteBuilder; use Megio\Collection\WriteBuilder\WriteBuilderEvent; use Megio\Collection\Exception\CollectionException; @@ -92,11 +92,11 @@ public function process(array $data): Response return $dispatcher->getResponse(); } - $recipeRequest = new RecipeRequest($this->request, false, $row['id'], $row['data'], $data['custom_data']); + $collectionRequest = new CollectionRequest($this->request, false, $data, $row['id'], $row['data']); try { $builder = $recipe - ->update($this->builder->create($recipe, WriteBuilderEvent::UPDATE, $row['id'], $row['data']), $recipeRequest) + ->update($this->builder->create($recipe, WriteBuilderEvent::UPDATE, $row['id'], $row['data']), $collectionRequest) ->build(); } catch (CollectionException $e) { $response = $this->error([$e->getMessage()], 406); diff --git a/src/Recipe/AdminRecipe.php b/src/Recipe/AdminRecipe.php index 8ee3031..13a6d3a 100644 --- a/src/Recipe/AdminRecipe.php +++ b/src/Recipe/AdminRecipe.php @@ -3,9 +3,9 @@ namespace Megio\Recipe; +use Megio\Collection\CollectionRequest; use Megio\Collection\ReadBuilder\Column\EmailColumn; use Megio\Collection\ReadBuilder\ReadBuilder; -use Megio\Collection\RecipeRequest; use Megio\Collection\WriteBuilder\Field\Base\EmptyValue; use Megio\Collection\WriteBuilder\WriteBuilder; use Megio\Collection\WriteBuilder\Field\EmailField; @@ -26,25 +26,25 @@ public function key(): string return 'admin'; } - public function read(ReadBuilder $builder, RecipeRequest $request): ReadBuilder + public function read(ReadBuilder $builder, CollectionRequest $request): ReadBuilder { return $builder->buildByDbSchema(['password']); } - public function readAll(ReadBuilder $builder, RecipeRequest $request): ReadBuilder + public function readAll(ReadBuilder $builder, CollectionRequest $request): ReadBuilder { return $builder->buildByDbSchema(['password'], persist: true) ->add(new EmailColumn('email', 'E-mail', true)); } - public function create(WriteBuilder $builder, RecipeRequest $request): WriteBuilder + public function create(WriteBuilder $builder, CollectionRequest $request): WriteBuilder { return $builder ->add(new EmailField('email', 'E-mail', [new RequiredRule()])) ->add(new PasswordField('password', 'Password', [new RequiredRule()])); } - public function update(WriteBuilder $builder, RecipeRequest $request): WriteBuilder + public function update(WriteBuilder $builder, CollectionRequest $request): WriteBuilder { $pwf = new PasswordField(name: 'password', label: 'Heslo'); diff --git a/src/Recipe/TestFieldsRecipe.php b/src/Recipe/TestFieldsRecipe.php index fe078b7..611c266 100644 --- a/src/Recipe/TestFieldsRecipe.php +++ b/src/Recipe/TestFieldsRecipe.php @@ -3,7 +3,8 @@ namespace Megio\Recipe; -use Megio\Collection\RecipeRequest; +use Megio\Collection\CollectionRecipe; +use Megio\Collection\CollectionRequest; use Megio\Collection\WriteBuilder\Field\ArrayField; use Megio\Collection\WriteBuilder\Field\DateCzField; use Megio\Collection\WriteBuilder\Field\DateField; @@ -34,7 +35,6 @@ use Megio\Collection\WriteBuilder\Rule\NullableRule; use Megio\Collection\WriteBuilder\Rule\RequiredRule; use Megio\Collection\WriteBuilder\WriteBuilder; -use Megio\Collection\CollectionRecipe; use Megio\Database\Entity\Admin; use Nette\Schema\Expect; @@ -50,7 +50,7 @@ public function key(): string return 'test-fields'; } - public function create(WriteBuilder $builder, RecipeRequest $request): WriteBuilder + public function create(WriteBuilder $builder, CollectionRequest $request): WriteBuilder { $items = [ new SelectField\Item(0, 'Test_1'), diff --git a/src/Recipe/TestRulesRecipe.php b/src/Recipe/TestRulesRecipe.php index fbd59c8..e8c85f7 100644 --- a/src/Recipe/TestRulesRecipe.php +++ b/src/Recipe/TestRulesRecipe.php @@ -3,7 +3,8 @@ namespace Megio\Recipe; -use Megio\Collection\RecipeRequest; +use Megio\Collection\CollectionRecipe; +use Megio\Collection\CollectionRequest; use Megio\Collection\WriteBuilder\Field\ArrayField; use Megio\Collection\WriteBuilder\Field\DateCzField; use Megio\Collection\WriteBuilder\Field\DateField; @@ -39,7 +40,6 @@ use Megio\Collection\WriteBuilder\Rule\NullableRule; use Megio\Collection\WriteBuilder\Rule\RegexRule; use Megio\Collection\WriteBuilder\Rule\RequiredRule; -use Megio\Collection\CollectionRecipe; use Megio\Collection\WriteBuilder\Rule\UniqueRule; use Megio\Database\Entity\Admin; use Nette\Schema\Expect; @@ -56,7 +56,7 @@ public function key(): string return 'test-rules'; } - public function create(WriteBuilder $builder, RecipeRequest $request): WriteBuilder + public function create(WriteBuilder $builder, CollectionRequest $request): WriteBuilder { $items = [ new SelectField\Item(0, 'Test_1'), @@ -148,7 +148,7 @@ public function create(WriteBuilder $builder, RecipeRequest $request): WriteBuil ->add(new DecimalField(name: 'decimal_required', label: '', rules: [new RequiredRule()], mapToEntity: false)); } - public function update(WriteBuilder $builder, RecipeRequest $request): WriteBuilder + public function update(WriteBuilder $builder, CollectionRequest $request): WriteBuilder { return $builder ->add(new TextField(name: 'email', label: '', rules: [