createListingResponse example


        $category = $this->getTestCategory($id);

        $col = new CategoryCollection([$category]);
        $criteria = new Criteria();
        $searchResult = new EntitySearchResult('product', 1, $col, null, $criteria$context);

        $definition = $this->getContainer()->get(CategoryDefinition::class);
        $request = Request::create($path, 'GET', [][][]['HTTP_ACCEPT' => $accept]);
        $this->setOrigin($request$context);

        return $this->getFactory($request)->createListingResponse($criteria$searchResult$definition$request$context);
    }

    private function getTestCategory(string $id): CategoryEntity
    {
        $category = new CategoryEntity();
        $category->setId($id);
        $category->setName($id);
        $category->internalSetEntityData('category', new FieldVisibility([]));

        return $category;
    }

    

    }

    public function search(Request $request, Context $context, ResponseFactoryInterface $responseFactory, string $entityName, string $path): Response
    {
        [$criteria$repository] = $this->resolveSearch($request$context$entityName$path);

        $result = $context->scope(Context::CRUD_API_SCOPE, fn (Context $context): EntitySearchResult => $repository->search($criteria$context));

        $definition = $this->getDefinitionOfPath($entityName$path$context);

        return $responseFactory->createListingResponse($criteria$result$definition$request$context);
    }

    public function list(Request $request, Context $context, ResponseFactoryInterface $responseFactory, string $entityName, string $path): Response
    {
        [$criteria$repository] = $this->resolveSearch($request$context$entityName$path);

        $result = $context->scope(Context::CRUD_API_SCOPE, fn (Context $context): EntitySearchResult => $repository->search($criteria$context));

        $definition = $this->getDefinitionOfPath($entityName$path$context);

        return $responseFactory->createListingResponse($criteria$result$definition$request$context);
    }
Home | Imprint | This part of the site doesn't use cookies.