createDetailResponse example

$stateFieldName = (string) $request->query->get('stateFieldName', 'stateId');
        $stateMachineStateCollection = $this->stateMachineRegistry->transition(
            new Transition(
                $entityName,
                $entityId,
                $transition,
                $stateFieldName
            ),
            $context
        );

        return $responseFactory->createDetailResponse(
            new Criteria(),
            $stateMachineStateCollection->get('toPlace'),
            $this->definitionInstanceRegistry->get(StateMachineStateDefinition::class),
            $request,
            $context
        );
    }
}
static::assertArrayHasKey('included', $content);
    }

    private function getDetailResponse(Context $context, string $id, string $path, string $accept, bool $setLocationHeader): Response
    {
        $category = $this->getTestCategory($id);

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

        return $this->getFactory($request)->createDetailResponse(new Criteria()$category$definition$request$context$setLocationHeader);
    }

    private function getListResponse(Context $context, string $id, string $path, string $accept): Response
    {
        $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);
        
if (!$userId) {
            throw new ExpectedUserHttpException();
        }
        $criteria = new Criteria([$userId]);
        $criteria->addAssociation('aclRoles');

        $user = $this->userRepository->search($criteria$context)->first();
        if (!$user) {
            throw OAuthServerException::invalidCredentials();
        }

        return $responseFactory->createDetailResponse(new Criteria()$user$this->userDefinition, $request$context);
    }

    #[Route(path: '/api/_info/me', name: 'api.change.me', defaults: ['auth_required' => true, '_acl' => ['user_change_me']], methods: ['PATCH'])]     public function updateMe(Context $context, Request $request, ResponseFactoryInterface $responseFactory): Response
    {
        if (!$context->getSource() instanceof AdminApiSource) {
            throw new InvalidContextSourceException(AdminApiSource::class$context->getSource()::class);
        }

        $userId = $context->getSource()->getUserId();
        if (!$userId) {
            
if (!empty($permissions)) {
            throw ApiException::missingPrivileges($permissions);
        }

        $entity = $context->scope(Context::CRUD_API_SCOPE, fn (Context $context): ?Entity => $repository->search($criteria$context)->get($id));

        if ($entity === null) {
            throw ApiException::resourceNotFound($definition->getEntityName()['id' => $id]);
        }

        return $responseFactory->createDetailResponse($criteria$entity$definition$request$context);
    }

    public function searchIds(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): IdSearchResult => $repository->searchIds($criteria$context));

        return new JsonResponse([
            'total' => $result->getTotal(),
            'data' => array_values($result->getIds()),
        ]);
Home | Imprint | This part of the site doesn't use cookies.