-
Notifications
You must be signed in to change notification settings - Fork 11
Bug 38050 - /lists #136
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
base: main
Are you sure you want to change the base?
Bug 38050 - /lists #136
Conversation
mrenvoize
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We'll also need unit tests.. examples in t/db_dependent/api
Koha/REST/V1/Lists.pm
Outdated
| =cut | ||
|
|
||
| sub list { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This whole routine is rather custom without any real need for it to be.. please follow the patterns set in all the other API controllers... i.e. using the API helpers so we get all the search and query handling from there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You'll want to follow Tomas's example to some extent here and use:
my $lists_set = Koha::Virtualshelves->new;
$lists_set = $lists_set->filter_by_readable( { patron_id => $user->id } );
return $c->render(
status => 200,
openapi => $c->objects->search($lists_set),
);He's also got error handling in a wrapper.. you'll likely want that too for various failure cases the object searches can throw.
Koha/REST/V1/Lists.pm
Outdated
| return $c->render(status => 201, json => { id => $list->id }); | ||
| } | ||
|
|
||
| =head3 read |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please call this method 'get'.. 'read' is a homonym for a Perl builtin so can sometimes be confused... also, that would make this consistent with other controllers.
Koha/REST/V1/Lists.pm
Outdated
| return $c->render(json => \@lists); | ||
| } | ||
|
|
||
| =head3 create |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please call this 'add' rather than 'create' for consistency with other API controllers.
Koha/REST/V1/Lists.pm
Outdated
| =cut | ||
|
|
||
| sub create { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is another case where you've not used the foundations that have been laid out before you.
See the 'Cities' controller for reference as it's generally the most basic 'best practices' example... I should have pointed you to that.. assuming I didn't already.
sub add {
my $c = shift->openapi->valid_input or return;
return try {
my $city = Koha::City->new_from_api( $c->req->json );
$city->store;
$c->res->headers->location( $c->req->url->to_string . '/' . $city->cityid );
return $c->render(
status => 201,
openapi => $c->objects->to_api($city),
);
}
catch {
$c->unhandled_exception($_);
};
}
Koha/REST/V1/Lists.pm
Outdated
| } | ||
| } | ||
|
|
||
| return $c->render(status => 201, json => { id => $list->id }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As above.. by using 'json' as your output directly, you're skipping all validation... please use the 'openapi' output handler as that include validation against the specification files.
Koha/REST/V1/Lists.pm
Outdated
| =cut | ||
|
|
||
| sub read { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a pattern for this one too:
sub get {
my $c = shift->openapi->valid_input or return;
return try {
my $city = Koha::Cities->find( $c->param('city_id') );
return $c->render_resource_not_found("City")
unless $city;
return $c->render( status => 200, openapi => $c->objects->to_api($city), );
} catch {
$c->unhandled_exception($_);
};
}I think you'll likely need to use the above mentioned filter_by_readable method however to ensure only those with appropriate access permissions can 'get' the specific list.
| =cut | ||
|
|
||
| sub update { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's another template for this:
sub update {
my $c = shift->openapi->valid_input or return;
my $city = Koha::Cities->find( $c->param('city_id') );
return $c->render_resource_not_found("City")
unless $city;
return try {
$city->set_from_api( $c->req->json );
$city->store();
return $c->render( status => 200, openapi => $c->objects->to_api($city), );
}
catch {
$c->unhandled_exception($_);
};
}We'll want to think about how we handle adding and removing biblios to/from lists.. lets keep the basic crud at the list level only however.
| =cut | ||
|
|
||
| sub delete { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again.. there's a template:
sub delete {
my $c = shift->openapi->valid_input or return;
my $city = Koha::Cities->find( $c->param('city_id') );
return $c->render_resource_not_found("City")
unless $city;
return try {
$city->delete;
return $c->render_resource_deleted;
}
catch {
$c->unhandled_exception($_);
};
}63ccb55 to
f012bae
Compare
f012bae to
c707f89
Compare
c707f89 to
10ab8c2
Compare
PTFS Europe is now officially Open Fifth Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> Signed-off-by: Paul Derscheid <paul.derscheid@lmscloud.de> Bug 39447: (follow-up) Corrections to existing mappings I thought it worked through from top to bottom and thus the lower down mappings would correct the higher up ones.. I was mistaken, thanks Jonathan for pointing that out Test with: 1. `git shortlog --summary --numbered --email | grep ptfs-e` 2. `git shortlog --summary --numbered --email | grep openfifth` Amended-by: Jonathan Druart Space adjustements Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
This patch fixes koha-upgrade-schema so that it returns an exit code of 0 whether or not a DB change is needed. This is important so that koha-common.postinst proceeds correctly even when there is no DB change needed (e.g. for 24.11.03-2) Test plan: 0. Apply the patch 1. cp debian/scripts/koha-upgrade-schema /usr/sbin/koha-upgrade-schema 2. dpkg-reconfigure koha-common 3. Note the process completes correctly 4. koha-upgrade-schema kohadev 5. Note following text appears very quickly: Upgrading database schema for kohadev No database change required 6. koha-mysql kohadev update systempreferences set value = '24.1102000' where variable = 'Version'; 7. Clear memcached 8. koha-upgrade-schema kohadev 9. Note that it applies the 24.11.03 database upgrade Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org> Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk> Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
10ab8c2 to
fbdd9ca
Compare
This patch creates the yaml definitions for the CRUD enpoints for virtualshelves/lists
This patch implements the methods for the admin CRUD endpoints for lists/virtualshelves
This patch creates the yaml definitions for the public CRUD enpoints for lists/virtualshelves
This patch creates the methods for the public CRUD enpoints for lists/virtualshelves
fbdd9ca to
306b44b
Compare
306b44b to
cc3a4eb
Compare
No description provided.