Skip to content

Proposal: Ability to specify identifier property of custom item operations #2126

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

soyuka
Copy link
Member

@soyuka soyuka commented Jul 25, 2018

Q A
Bug fix? not really
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? (need to add tests)
Fixed tickets #2116
License MIT
Doc PR todo

When declaring a custom item operation, you often want to use another property as identifier, for example:

<?php
/**
 * @ApiResource(itemOperations={
 *     "get",
 *     "put",
 *     "get_by_isbn"={"method"="GET", "path"="/books/by_isbn/{isbn}.{_format}", "requirements"={"isbn"=".+"}}
 * })
 */
class Book {}

Today, this only works if you add a custom controller, either by using your own data or by calling the core data provider with new identifiers ['isbn' => 1].

My proposal is to add a property in the operation route defaults:

<?php
/*
 * @ApiResource(itemOperations={
 *     "get",
 *     "put",
 *     "get_by_isbn"={"method"="GET", "path"="/books/by_isbn/{isbn}.{_format}", "requirements"={"isbn"=".+"}, "defaults"={"identifiedBy"="isbn"}}
 * })
 */
class Book {}

By using this you have nothing else to add (no controller, no data provider), it'll just use the isbn property as identifier.

This is a WIP, to be done:

  • accept proposal
  • add tests

@soyuka soyuka changed the title WIP: Ability to specify identifier property of custom item operations Proposal: Ability to specify identifier property of custom item operations Feb 15, 2019
@ziiko10
Copy link

ziiko10 commented Nov 18, 2019

Hello
I want to use custom identifier in a custom action without using {id} like this .

 @ApiResource(
   itemOperations={
     "FORGOT-PASSWORD"={
      "method"="PUT",
      "path"="/users/{forgotPasswordToken}/forgot-password",
      "controller"="App\Controller\ForgotPasswordController",
      "defaults"={"identifiedBy"="forgotPasswordToken"}
      }
    }
  )

But i still have the same error with "Invalid identifier value or configuration" .

Any issue please ?

@teohhanhui
Copy link
Contributor

This should probably not be in the route defaults.

@teohhanhui
Copy link
Contributor

@AbbesBendaoud10 It's not implemented yet.

@soyuka
Copy link
Member Author

soyuka commented Nov 21, 2019

This should probably not be in the route defaults.

👍 should be a new attribute

@hafkenscheid
Copy link

Any news regarding this?

@soyuka soyuka force-pushed the easier-custom-operations branch from e006023 to 2010727 Compare July 27, 2020 19:29
@lamb0tiana
Copy link

@soyuka @AbbesBendaoud10 how did you resolved that, I spent 2 days but nothing, would you help please, thank you.

@ziiko10
Copy link

ziiko10 commented Aug 6, 2020

@lamb0tiana i did it with "_api_receive"=false.

@soyuka
Copy link
Member Author

soyuka commented Aug 7, 2020

Use a custom route with a custom controller / data provider.

@souhaiboutoure
Copy link

@lamb0tiana i did it with "_api_receive"=false.

@AbbesBendaoud10 Thanks it worked for me 🥇

@soyuka
Copy link
Member Author

soyuka commented Oct 20, 2020

#3664

@soyuka soyuka closed this Oct 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants