Bug 23285 - Add patrons PATCH route
Summary: Add patrons PATCH route
Status: ASSIGNED
Alias: None
Product: Koha
Classification: Unclassified
Component: REST API (show other bugs)
Version: Main
Hardware: All All
: P5 - low enhancement (vote)
Assignee: Johanna Räisä
QA Contact:
URL:
Keywords:
Depends on: 23843
Blocks:
  Show dependency treegraph
 
Reported: 2019-07-09 08:36 UTC by Johanna Räisä
Modified: 2024-03-21 12:59 UTC (History)
4 users (show)

See Also:
Change sponsored?: Sponsored
Patch complexity: ---
Documentation contact:
Documentation submission:
Text to go in the release notes:
Version(s) released in:


Attachments
Bug 23285: Add patrons PATCH route (17.03 KB, patch)
2019-07-09 09:02 UTC, Johanna Räisä
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description Johanna Räisä 2019-07-09 08:36:04 UTC
Patron PATCH route is not yet implemented. PUT route is not exactly overwriting all data but there are some parameters which are required. PATCH route should accept updates from one to n fields.
Comment 1 Johanna Räisä 2019-07-09 09:02:48 UTC
Created attachment 91426 [details] [review]
Bug 23285: Add patrons PATCH route

Implementation for patrons PATCH route.

Test plan
- Apply this patch
- Run prove t/db_dependent/api/v1/patrons.t
- Create user with borrowers permissions
- Authenticate with the user created above and get a CGISESSION id.
- Use the CGISESSION to patch patrons via the API
- PATCH /patrons/{patron_id} with some parameters in the body

Sponsored-by: Koha-Suomi Oy
Comment 2 Joonas Kylmälä 2019-10-22 08:37:10 UTC
Please make this depend on #23843 so it doesn't conflict with it if it is pushed soon
Comment 3 Katrin Fischer 2019-10-22 12:12:20 UTC
Be careful with the "In Discussion" - maybe better to use FQA or back to Assigned?
Comment 4 Martin Renvoize 2019-10-28 09:16:50 UTC
Hmm.. 

At a quick glance this doesn't feel right.. somehow I feel like PATCH operations should utilise something like json-patch and send a list of change operations rather than just a partial copy of a whole object.
Comment 5 Katrin Fischer 2023-10-08 11:39:48 UTC
We do have "Update patron" with PUT in the API documentation - does this cover the use case?
https://api.koha-community.org/#tag/patrons/operation/updatePatron
Comment 6 Johanna Räisä 2023-10-25 10:36:26 UTC
(In reply to Katrin Fischer from comment #5)
> We do have "Update patron" with PUT in the API documentation - does this
> cover the use case?
> https://api.koha-community.org/#tag/patrons/operation/updatePatron

This endpoint is mentioned on this documentation.
https://wiki.koha-community.org/wiki/Patrons_endpoint_RFC

The difference between PUT and PATCH is that PUT updates the entire resource and PATCH updates only partial of the data without modifying the entire data.

At moment if you want to update one value, you need to update them all.

I guess Martin's comment was how is the response showed, correct me if I'm wrong.
Comment 7 Katrin Fischer 2023-10-25 11:11:25 UTC
(In reply to Johanna Räisä from comment #6)
> (In reply to Katrin Fischer from comment #5)
> > We do have "Update patron" with PUT in the API documentation - does this
> > cover the use case?
> > https://api.koha-community.org/#tag/patrons/operation/updatePatron
> 
> This endpoint is mentioned on this documentation.
> https://wiki.koha-community.org/wiki/Patrons_endpoint_RFC
> 
> The difference between PUT and PATCH is that PUT updates the entire resource
> and PATCH updates only partial of the data without modifying the entire data.
> 
> At moment if you want to update one value, you need to update them all.
> 
> I guess Martin's comment was how is the response showed, correct me if I'm
> wrong.

Hi Johanna, I believe we do also support partial with PUT even if it might not be totally clear from documentation.
Comment 8 Fridolin Somers 2024-03-20 13:47:09 UTC
I've tested and I cant do partial update with PUT.
I get "missing property" message.

I think since for both post and put we define for body :
        schema:
          $ref: "../swagger.yaml#/definitions/patron"

And in /api/v1/swagger/definitions/patron.yaml we have:
required:
  - surname
  - library_id
  - category_id
Comment 9 Katrin Fischer 2024-03-20 21:30:25 UTC
(In reply to Fridolin Somers from comment #8)
> I've tested and I cant do partial update with PUT.
> I get "missing property" message.
> 
> I think since for both post and put we define for body :
>         schema:
>           $ref: "../swagger.yaml#/definitions/patron"
> 
> And in /api/v1/swagger/definitions/patron.yaml we have:
> required:
>   - surname
>   - library_id
>   - category_id

It works, but you need to include those three always right now. (I just recently looked into that and we had discussed it on IRC)
Comment 10 Fridolin Somers 2024-03-21 12:59:03 UTC
I've been discussing this in mailing list koha-devel (REST API : PUT for partial update​).

So we do need a PATCH route.
It would be very useful to update for example the expiration date.

Is there a way to set required fields outside api/v1/swagger/definitions/patron.yaml so that is can be used in both PATCH,PUT and POST routes ?