Skip to content

Rewrite v7 find-user-by-identity tutorial - #171

Merged
arhimede merged 1 commit into
mainfrom
find-user-by-identity-rewrite
Sep 8, 2026
Merged

Rewrite v7 find-user-by-identity tutorial#171
arhimede merged 1 commit into
mainfrom
find-user-by-identity-rewrite

Conversation

@arhimede

@arhimede arhimede commented Sep 8, 2026

Copy link
Copy Markdown
Member

Audit finding C7. The tutorial was still a v5 page: every class, namespace and API in it is gone.

Verified against dotkernel/api branch 7.0 at 45ad282.

What was wrong

Docs said Code says
$app->get('/user/' . $id, UserHandler::class, 'user.view') $routeCollector->group('/user/' . $id)->get('', GetUserResourceHandler::class, 'user::view-user')
UserHandler with a get() method GetUserResourceHandler with handle()
use Api\App\Handler\HandlerTrait; no such trait — extend Api\App\Handler\AbstractHandler
use Api\App\Message; Core\App\Message
use Api\User\Entity\User; Core\User\Entity\User
(new BadRequestException())->setMessages([...]) setMessages() exists nowhere
throw new NotFoundException(Message::USER_NOT_FOUND) NotFoundException::create(...)
UserRole::ROLE_GUEST UserRoleEnum::Guest->value
test asserts $messages['error']['messages'][0] problem details, so detail
dot-notation route names, three-column route:list :: names, four-column table

What the page does now

It follows the endpoint it claims to follow. In v7 GetUserResourceHandler never queries the database — ResourceProviderMiddleware reads the #[Resource] attribute off handle() and loads the entity. So the new endpoint is one attribute:

#[Resource(entity: User::class, identifier: 'identity', placeholder: 'identity')]

which the middleware turns into findOneBy(['identity' => ...]), throwing NotFoundException itself when nothing matches. The old page's BadRequestException branch was unreachable in any version — /user/ matches no route.

Also corrected:

  • Registration needs two entries, not one: factories and delegators => [HandlerDelegatorFactory::class]. Without the delegator, $responseFactory stays null and createResponse() fails.
  • Why the route goes last is now the real reason: /user/{id} is UUID-constrained and {identity} is not, so a UUID matches both; static paths like /user/role were never at risk.
  • MetadataMap needs no new entry_links.self still points at /user/{uuid}.
  • Tests assert the problem details body, with the two 404s explained (unmatched route vs. thrown exception).

markdownlint clean, one sentence per line.

The v5 handler shape, `Api\App` namespaces and `setMessages()` no longer exist; the endpoint is now a `#[Resource]` attribute resolved by ResourceProviderMiddleware.

Signed-off-by: arhimede <julian@dotkernel.com>
@arhimede
arhimede requested a review from alexmerlin September 8, 2026 16:11
@arhimede
arhimede merged commit 5a53ede into main Sep 8, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants