Skip to content

Conversation

@mrenvoize
Copy link
Member

No description provided.

Copy link
Member Author

@mrenvoize mrenvoize left a 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

=cut

sub list {
Copy link
Member Author

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.

Copy link
Member Author

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.

return $c->render(status => 201, json => { id => $list->id });
}

=head3 read
Copy link
Member Author

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.

return $c->render(json => \@lists);
}

=head3 create
Copy link
Member Author

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.

=cut

sub create {
Copy link
Member Author

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($_);
    };
}

}
}

return $c->render(status => 201, json => { id => $list->id });
Copy link
Member Author

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.

=cut

sub read {
Copy link
Member Author

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 {
Copy link
Member Author

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 {
Copy link
Member Author

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($_);
    };
}

mrenvoize and others added 2 commits March 26, 2025 12:28
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>
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants