[Bug 24528] New: Add a syntax for specifying counts on x-koha-embed
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=24528 Bug ID: 24528 Summary: Add a syntax for specifying counts on x-koha-embed Change sponsored?: --- Product: Koha Version: master Hardware: All OS: All Status: NEW Severity: enhancement Priority: P5 - low Component: REST API Assignee: koha-bugs@lists.koha-community.org Reporter: tomascohen@gmail.com We need a way to specify that we want the count of the relation result and not the result itself, this way we don't need to implement *_count methods (see bug 24467) -- You are receiving this mail because: You are watching all bug changes. You are the assignee for the bug.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=24528 Tomás Cohen Arazi <tomascohen@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Assignee|koha-bugs@lists.koha-commun |tomascohen@gmail.com |ity.org | Status|NEW |ASSIGNED Blocks| |24467 Referenced Bugs: https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=24467 [Bug 24467] *_count methods should be avoided -- You are receiving this mail because: You are the assignee for the bug. You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=24528 --- Comment #1 from Tomás Cohen Arazi <tomascohen@gmail.com> --- Created attachment 98046 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=98046&action=edit Bug 24528: Unit tests for Koha::Object->to_api This patch introduces unit tests for the new to_api bejaviour for *_count methods. To test: 1. Apply this patch 2. Run: $ kshell k$ prove t/db_dependent/Koha/Object.t => FAIL: Tests fail because the feature is not implemented -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=24528 --- Comment #2 from Tomás Cohen Arazi <tomascohen@gmail.com> --- Created attachment 98047 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=98047&action=edit Bug 24528: Add *_count support to to_api This patch adds a way to tell to_api an attribute needs to be calculated as the count on an existing method/relationship result. For example, if we wanted to include the holds_count attribute for a Koha::Patron object, we would call it: $ patron_json = $patron->to_api({ embed => { holds_count => { is_count => 1 } } }); This way to_api will internally call $json->{holds_count} = $self->holds->count; To test: 1. Apply the tests patch 2. Run: $ kshell k$ prove t/db_dependent/Koha/Object.t => FAIL: Tests fail! 3. Apply this patch 4. Repeat (2) => SUCCESS: Tests pass! 5. Sign off :-D -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=24528 Tomás Cohen Arazi <tomascohen@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |agustinmoyano@theke.io, | |jonathan.druart@bugs.koha-c | |ommunity.org, | |martin.renvoize@ptfs-europe | |.com --- Comment #3 from Tomás Cohen Arazi <tomascohen@gmail.com> --- Submitting the first bit once I got it for review. It is pretty simple, but I had a nightmare because I picked Koha::Biblio as an example... Will need to fix the overloaded to_api once I get this sorted. Next step is parsing relation+count on the API code, and adding is_count => 1 to the structure. -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=24528 --- Comment #4 from Tomás Cohen Arazi <tomascohen@gmail.com> --- Created attachment 98065 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=98065&action=edit Bug 24528: Add a syntax to x-koha-embed to specify counts This patch adds a + syntax to specify on the x-koha-embed header that we want the count of a relation in the response. For example: GET /patrons/1 x-koha-embed: checkouts+count Would return a JSON representation of a Koha::Patron, with a new attribute added: checkouts_count, which will be the result of calling $patron->checkouts->count. This is all done automatically in to_api. This patch makes parsing the x-koha-embed header build the right structure for passing to the to_api method. To test: 1. Apply this patch 2. Run: $ kshell k$ prove t/Koha/REST/Plugin/Query.t => SUCCESS: Tests pass! 3. Sign off :-D Sponsored-by: ByWater Solutions -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=24528 Tomás Cohen Arazi <tomascohen@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|ASSIGNED |Needs Signoff --- Comment #5 from Tomás Cohen Arazi <tomascohen@gmail.com> --- Ready for testing! -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=24528 Tomás Cohen Arazi <tomascohen@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |joonas.kylmala@helsinki.fi, | |josef.moravec@gmail.com, | |kyle@bywatersolutions.com, | |nick@bywatersolutions.com -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=24528 Tomás Cohen Arazi <tomascohen@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |m.de.rooy@rijksmuseum.nl -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=24528 Tomás Cohen Arazi <tomascohen@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Blocks| |20212 Referenced Bugs: https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=20212 [Bug 20212] Slowness in Receiving in Acquisitions -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=24528 David Nind <david@davidnind.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|Needs Signoff |Signed Off -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=24528 David Nind <david@davidnind.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Attachment #98046|0 |1 is obsolete| | --- Comment #6 from David Nind <david@davidnind.com> --- Created attachment 98199 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=98199&action=edit Bug 24528: Unit tests for Koha::Object->to_api This patch introduces unit tests for the new to_api bejaviour for *_count methods. To test: 1. Apply this patch 2. Run: $ kshell k$ prove t/db_dependent/Koha/Object.t => FAIL: Tests fail because the feature is not implemented Signed-off-by: David Nind <david@davidnind.com> -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=24528 David Nind <david@davidnind.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Attachment #98047|0 |1 is obsolete| | --- Comment #7 from David Nind <david@davidnind.com> --- Created attachment 98200 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=98200&action=edit Bug 24528: Add *_count support to to_api This patch adds a way to tell to_api an attribute needs to be calculated as the count on an existing method/relationship result. For example, if we wanted to include the holds_count attribute for a Koha::Patron object, we would call it: $ patron_json = $patron->to_api({ embed => { holds_count => { is_count => 1 } } }); This way to_api will internally call $json->{holds_count} = $self->holds->count; To test: 1. Apply the tests patch 2. Run: $ kshell k$ prove t/db_dependent/Koha/Object.t => FAIL: Tests fail! 3. Apply this patch 4. Repeat (2) => SUCCESS: Tests pass! 5. Sign off :-D Signed-off-by: David Nind <david@davidnind.com> -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=24528 David Nind <david@davidnind.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Attachment #98065|0 |1 is obsolete| | --- Comment #8 from David Nind <david@davidnind.com> --- Created attachment 98201 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=98201&action=edit Bug 24528: Add a syntax to x-koha-embed to specify counts This patch adds a + syntax to specify on the x-koha-embed header that we want the count of a relation in the response. For example: GET /patrons/1 x-koha-embed: checkouts+count Would return a JSON representation of a Koha::Patron, with a new attribute added: checkouts_count, which will be the result of calling $patron->checkouts->count. This is all done automatically in to_api. This patch makes parsing the x-koha-embed header build the right structure for passing to the to_api method. To test: 1. Apply this patch 2. Run: $ kshell k$ prove t/Koha/REST/Plugin/Query.t => SUCCESS: Tests pass! 3. Sign off :-D Sponsored-by: ByWater Solutions Signed-off-by: David Nind <david@davidnind.com> Signed-off-by: David Nind <david@davidnind.com> -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=24528 Marcel de Rooy <m.de.rooy@rijksmuseum.nl> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|Signed Off |BLOCKED --- Comment #9 from Marcel de Rooy <m.de.rooy@rijksmuseum.nl> --- QAing -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=24528 Marcel de Rooy <m.de.rooy@rijksmuseum.nl> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|BLOCKED |Passed QA Patch complexity|--- |Small patch -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=24528 Marcel de Rooy <m.de.rooy@rijksmuseum.nl> changed: What |Removed |Added ---------------------------------------------------------------------------- Attachment #98199|0 |1 is obsolete| | --- Comment #10 from Marcel de Rooy <m.de.rooy@rijksmuseum.nl> --- Created attachment 98212 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=98212&action=edit Bug 24528: Unit tests for Koha::Object->to_api This patch introduces unit tests for the new to_api bejaviour for *_count methods. To test: 1. Apply this patch 2. Run: $ kshell k$ prove t/db_dependent/Koha/Object.t => FAIL: Tests fail because the feature is not implemented Signed-off-by: David Nind <david@davidnind.com> Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=24528 Marcel de Rooy <m.de.rooy@rijksmuseum.nl> changed: What |Removed |Added ---------------------------------------------------------------------------- Attachment #98200|0 |1 is obsolete| | --- Comment #11 from Marcel de Rooy <m.de.rooy@rijksmuseum.nl> --- Created attachment 98213 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=98213&action=edit Bug 24528: Add *_count support to to_api This patch adds a way to tell to_api an attribute needs to be calculated as the count on an existing method/relationship result. For example, if we wanted to include the holds_count attribute for a Koha::Patron object, we would call it: $ patron_json = $patron->to_api({ embed => { holds_count => { is_count => 1 } } }); This way to_api will internally call $json->{holds_count} = $self->holds->count; To test: 1. Apply the tests patch 2. Run: $ kshell k$ prove t/db_dependent/Koha/Object.t => FAIL: Tests fail! 3. Apply this patch 4. Repeat (2) => SUCCESS: Tests pass! 5. Sign off :-D Signed-off-by: David Nind <david@davidnind.com> Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=24528 Marcel de Rooy <m.de.rooy@rijksmuseum.nl> changed: What |Removed |Added ---------------------------------------------------------------------------- Attachment #98201|0 |1 is obsolete| | --- Comment #12 from Marcel de Rooy <m.de.rooy@rijksmuseum.nl> --- Created attachment 98214 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=98214&action=edit Bug 24528: Add a syntax to x-koha-embed to specify counts This patch adds a + syntax to specify on the x-koha-embed header that we want the count of a relation in the response. For example: GET /patrons/1 x-koha-embed: checkouts+count Would return a JSON representation of a Koha::Patron, with a new attribute added: checkouts_count, which will be the result of calling $patron->checkouts->count. This is all done automatically in to_api. This patch makes parsing the x-koha-embed header build the right structure for passing to the to_api method. To test: 1. Apply this patch 2. Run: $ kshell k$ prove t/Koha/REST/Plugin/Query.t => SUCCESS: Tests pass! 3. Sign off :-D Sponsored-by: ByWater Solutions Signed-off-by: David Nind <david@davidnind.com> Signed-off-by: David Nind <david@davidnind.com> Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=24528 Marcel de Rooy <m.de.rooy@rijksmuseum.nl> changed: What |Removed |Added ---------------------------------------------------------------------------- QA Contact| |m.de.rooy@rijksmuseum.nl -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=24528 --- Comment #13 from Jonathan Druart <jonathan.druart@bugs.koha-community.org> --- + if ( $embed =~ m/^(?<relation>.*)_count$/ and + if ( $curr =~ m/^(?<relation>.*)\+count/ ) { + my $key = $+{relation} . "_count"; Why did not you keep "relation+count"? -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=24528 --- Comment #14 from Tomás Cohen Arazi <tomascohen@gmail.com> --- (In reply to Jonathan Druart from comment #13)
+ if ( $embed =~ m/^(?<relation>.*)_count$/
and
+ if ( $curr =~ m/^(?<relation>.*)\+count/ ) { + my $key = $+{relation} . "_count";
Why did not you keep "relation+count"?
Inertia. Coding at 2 am. I agree with keeping the +. -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=24528 Tomás Cohen Arazi <tomascohen@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Blocks| |24554 Referenced Bugs: https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=24554 [Bug 24554] Only embed relations from Koha::Biblio in to_api -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=24528 Martin Renvoize <martin.renvoize@ptfs-europe.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Version(s)| |20.05.00 released in| | Status|Passed QA |Pushed to master -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=24528 --- Comment #15 from Martin Renvoize <martin.renvoize@ptfs-europe.com> --- Nice work everyone! Pushed to master for 20.05 -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=24528 --- Comment #16 from Tomás Cohen Arazi <tomascohen@gmail.com> --- (In reply to Tomás Cohen Arazi from comment #14)
(In reply to Jonathan Druart from comment #13)
+ if ( $embed =~ m/^(?<relation>.*)_count$/
and
+ if ( $curr =~ m/^(?<relation>.*)\+count/ ) { + my $key = $+{relation} . "_count";
Why did not you keep "relation+count"?
Inertia. Coding at 2 am. I agree with keeping the +.
We decided to keep with the snake_case syntax as using + would (1) not follow the API naming conventions, and (2) it would become problematic to access the hash elements i.e. order.biblio+count means concatenating order.biblio and count. -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=24528 Joy Nelson <joy@bywatersolutions.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|Pushed to master |RESOLVED Resolution|--- |FIXED CC| |joy@bywatersolutions.com --- Comment #17 from Joy Nelson <joy@bywatersolutions.com> --- Enhancement not backported to 19.11.x -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=24528 Tomás Cohen Arazi <tomascohen@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Blocks| |24965 Referenced Bugs: https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=24965 [Bug 24965] Koha::Object->to_api should handle undef counts -- You are receiving this mail because: You are watching all bug changes.
participants (1)
-
bugzilla-daemon@bugs.koha-community.org