Bug 31798

Summary: Add POST endpoint for Items
Product: Koha Reporter: Nick Clemens <nick>
Component: REST APIAssignee: Agustín Moyano <agustinmoyano>
Status: RESOLVED FIXED QA Contact: Marcel de Rooy <m.de.rooy>
Severity: new feature    
Priority: P5 - low CC: jonathan.druart, kyle, m.de.rooy, martin.renvoize, tomascohen
Version: Main   
Hardware: All   
OS: All   
See Also: https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=32896
Change sponsored?: Sponsored Patch complexity: Small patch
Documentation contact: Documentation submission:
Text to go in the release notes:
Version(s) released in:
23.05.00
Bug Depends on: 31797    
Bug Blocks: 32896, 31789, 31799    
Attachments: Bug 31798: Add REST endpoint to add a biblio's item
Bug 31798: Add REST endpoint to add a biblio's item
Bug 31798: (follow-up) Tidy up camel cased variables and unnecessary checks
Bug 31798: (follow-up) Add duplicate barcode test
Bug 31798: (follow-up) Tidy up and add duplicate barcode test
Bug 31798: (follow-up) Handle all values of autoBarcode
Bug 31798: (follow-up) Handle all values of autoBarcode
Bug 31798: Add REST endpoint to add a biblio's item
Bug 31798: (follow-up) Tidy up and add duplicate barcode test
Bug 31798: (follow-up) Handle all values of autoBarcode
Bug 31798: Add REST endpoint to add a biblio's item
Bug 31798: (follow-up) Tidy up and add duplicate barcode test
Bug 31798: (follow-up) Handle all values of autoBarcode
Bug 31798: Add REST endpoint to add a biblio's item
Bug 31798: Add REST endpoint to add a biblio's item
Bug 31798: (follow-up) Tidy up and add duplicate barcode test
Bug 31798: (follow-up) Handle all values of autoBarcode
Bug 31798: (QA follow-up) Remove use Koha::Item, we already use Koha::Items

Description Nick Clemens 2022-10-14 14:38:53 UTC

    
Comment 1 Agustín Moyano 2022-12-30 15:42:38 UTC
Created attachment 144893 [details] [review]
Bug 31798: Add REST endpoint to add a biblio's item

To test:
1. Apply patch
2. Set RESTBasicAuth preference to true
3. Get a biblio
4. Make a POST request to /api/v1/biblios/:biblio_id/items with a json body that represents the new item
5. Check that the item is created
6. Sign off
Comment 2 Lucas Gass 2022-12-30 16:14:37 UTC
Created attachment 144894 [details] [review]
Bug 31798: Add REST endpoint to add a biblio's item

To test:
1. Apply patch
2. Set RESTBasicAuth preference to true
3. Get a biblio
4. Make a POST request to /api/v1/biblios/:biblio_id/items with a json body that represents the new item
5. Check that the item is created
6. Sign off

Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
Comment 3 Agustín Moyano 2023-01-03 17:44:27 UTC
Created attachment 144952 [details] [review]
Bug 31798: (follow-up) Tidy up camel cased variables and unnecessary checks
Comment 4 Tomás Cohen Arazi 2023-01-03 17:47:46 UTC
Agustin, I think this is missing tests for the duplicate barcode use case. And in those tests it should be returning a 409 (conflict?) instead of a 500 because of the unhandled exception.

Thanks.
Comment 5 Agustín Moyano 2023-01-03 17:55:09 UTC
Created attachment 144953 [details] [review]
Bug 31798: (follow-up) Add duplicate barcode test
Comment 6 Agustín Moyano 2023-01-03 17:57:58 UTC
(In reply to Tomás Cohen Arazi from comment #4)
> Agustin, I think this is missing tests for the duplicate barcode use case.
> And in those tests it should be returning a 409 (conflict?) instead of a 500
> because of the unhandled exception.
> 
> Thanks.

Should we return 409 conflict or 400 bad request?

Thanks
Comment 7 Agustín Moyano 2023-01-03 18:32:32 UTC
Created attachment 144956 [details] [review]
Bug 31798: (follow-up) Tidy up and add duplicate barcode test
Comment 8 Martin Renvoize 2023-02-07 14:25:25 UTC
Aren't we being a bit nieve here in terms of autoBarcode?

I'm wondering:
1) Can we move the autoBarcode handling into Koha::Item->store() instead?
2) Even if we don't move the autoBarcode handling, don't we need to account for the other options it supports?
Comment 9 Agustín Moyano 2023-02-08 13:20:07 UTC
(In reply to Martin Renvoize from comment #8)
> Aren't we being a bit nieve here in terms of autoBarcode?
> 
> I'm wondering:
> 1) Can we move the autoBarcode handling into Koha::Item->store() instead?
> 2) Even if we don't move the autoBarcode handling, don't we need to account
> for the other options it supports?

Hi Martin, 

If I remove all about autoBarcode and link this to bug 32896, would it pass QA?

Thanks
Comment 10 Martin Renvoize 2023-02-27 14:23:12 UTC
Hmm, it would help move this bug.. but in my opinion it's moving towards blocked rather than PQA.

It's hard... I don't really want to block this one and asking for the autoBarcode move is a bit out of direct scope of this piece.
Comment 11 Nick Clemens 2023-02-27 17:58:01 UTC
Created attachment 147463 [details] [review]
Bug 31798: (follow-up) Handle all values of autoBarcode
Comment 12 Nick Clemens 2023-02-27 18:11:00 UTC
Created attachment 147464 [details] [review]
Bug 31798: (follow-up) Handle all values of autoBarcode
Comment 13 Nick Clemens 2023-02-27 18:11:49 UTC
(In reply to Martin Renvoize from comment #10)
> Hmm, it would help move this bug.. but in my opinion it's moving towards
> blocked rather than PQA.
> 
> It's hard... I don't really want to block this one and asking for the
> autoBarcode move is a bit out of direct scope of this piece.

Follow-up attached, crude, but lets us handle the move more elegantly on 32896
Comment 14 Martin Renvoize 2023-03-02 16:28:43 UTC
Created attachment 147655 [details] [review]
Bug 31798: Add REST endpoint to add a biblio's item

To test:
1. Apply patch
2. Set RESTBasicAuth preference to true
3. Get a biblio
4. Make a POST request to /api/v1/biblios/:biblio_id/items with a json body that represents the new item
5. Check that the item is created
6. Sign off

Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Comment 15 Martin Renvoize 2023-03-02 16:28:46 UTC
Created attachment 147656 [details] [review]
Bug 31798: (follow-up) Tidy up and add duplicate barcode test

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Comment 16 Martin Renvoize 2023-03-02 16:28:49 UTC
Created attachment 147657 [details] [review]
Bug 31798: (follow-up) Handle all values of autoBarcode

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Comment 17 Marcel de Rooy 2023-04-14 07:53:44 UTC
Applying: Bug 31798: (follow-up) Handle all values of autoBarcode
error: sha1 information is lacking or useless (Koha/REST/V1/Biblios.pm).
error: could not build fake ancestor
Patch failed at 0001 Bug 31798: (follow-up) Handle all values of autoBarcode
Comment 18 Agustín Moyano 2023-05-03 15:14:36 UTC
Created attachment 150598 [details] [review]
Bug 31798: Add REST endpoint to add a biblio's item

To test:
1. Apply patch
2. Set RESTBasicAuth preference to true
3. Get a biblio
4. Make a POST request to /api/v1/biblios/:biblio_id/items with a json body that represents the new item
5. Check that the item is created
6. Sign off

Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Comment 19 Agustín Moyano 2023-05-03 15:14:39 UTC
Created attachment 150599 [details] [review]
Bug 31798: (follow-up) Tidy up and add duplicate barcode test

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Comment 20 Agustín Moyano 2023-05-03 15:14:42 UTC
Created attachment 150600 [details] [review]
Bug 31798: (follow-up) Handle all values of autoBarcode

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Comment 21 Kyle M Hall 2023-05-05 15:27:25 UTC
Created attachment 150771 [details] [review]
Bug 31798: Add REST endpoint to add a biblio's item

To test:
1. Apply patch
2. Set RESTBasicAuth preference to true
3. Get a biblio
4. Make a POST request to /api/v1/biblios/:biblio_id/items with a json body that represents the new item
5. Check that the item is created
6. Sign off

Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Comment 22 Kyle M Hall 2023-05-05 15:38:41 UTC
Created attachment 150772 [details] [review]
Bug 31798: Add REST endpoint to add a biblio's item

To test:
1. Apply patch
2. Set RESTBasicAuth preference to true
3. Get a biblio
4. Make a POST request to /api/v1/biblios/:biblio_id/items with a json body that represents the new item
5. Check that the item is created
6. Sign off

Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Comment 23 Kyle M Hall 2023-05-05 15:38:48 UTC
Created attachment 150773 [details] [review]
Bug 31798: (follow-up) Tidy up and add duplicate barcode test

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Comment 24 Kyle M Hall 2023-05-05 15:38:50 UTC
Created attachment 150774 [details] [review]
Bug 31798: (follow-up) Handle all values of autoBarcode

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Comment 25 Kyle M Hall 2023-05-05 15:38:52 UTC
Created attachment 150775 [details] [review]
Bug 31798: (QA follow-up) Remove use Koha::Item, we already use Koha::Items

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Comment 26 Tomás Cohen Arazi 2023-05-05 18:42:59 UTC
Pushed to master for 23.05.

Nice work everyone, thanks!
Comment 27 Martin Renvoize 2023-05-12 15:33:07 UTC
Another API addition.. for now I'm choosing not to backport, but let me know if this is important to you and I'll look at backporting the whole tree.