|
Lines 16-32
package Koha::REST::V1::Lists;
Link Here
|
| 16 |
# along with Koha; if not, see <http://www.gnu.org/licenses>. |
16 |
# along with Koha; if not, see <http://www.gnu.org/licenses>. |
| 17 |
|
17 |
|
| 18 |
use Modern::Perl; |
18 |
use Modern::Perl; |
| 19 |
|
|
|
| 20 |
use Mojo::Base 'Mojolicious::Controller'; |
19 |
use Mojo::Base 'Mojolicious::Controller'; |
| 21 |
|
|
|
| 22 |
use Koha::Virtualshelves; |
20 |
use Koha::Virtualshelves; |
| 23 |
|
|
|
| 24 |
use Try::Tiny qw( catch try ); |
21 |
use Try::Tiny qw( catch try ); |
| 25 |
|
22 |
|
|
|
23 |
use Data::Dumper; |
| 24 |
|
| 26 |
=head1 API |
25 |
=head1 API |
| 27 |
|
26 |
|
| 28 |
=head2 Methods |
27 |
=head2 Methods |
| 29 |
|
28 |
|
|
|
29 |
=head3 list |
| 30 |
|
| 31 |
List all virtual shelves |
| 32 |
|
| 33 |
=cut |
| 34 |
|
| 35 |
sub list { |
| 36 |
my $c = shift->openapi->valid_input or return; |
| 37 |
|
| 38 |
return try { |
| 39 |
my $lists = $c->objects->search( Koha::Virtualshelves->new ); |
| 40 |
return $c->render( status => 200, openapi => $lists ); |
| 41 |
} catch { |
| 42 |
$c->unhandled_exception($_); |
| 43 |
}; |
| 44 |
|
| 45 |
} |
| 46 |
|
| 47 |
=head3 read |
| 48 |
|
| 49 |
List the contents of a virtual shelf |
| 50 |
|
| 51 |
=cut |
| 52 |
|
| 53 |
sub read { |
| 54 |
my $c = shift->openapi->valid_input or return; |
| 55 |
|
| 56 |
return try { |
| 57 |
my $list_id = Koha::Virtualshelves->find( $c->param('list_id') ); |
| 58 |
return $c->render_resource_not_found("list_id") |
| 59 |
unless $list_id; |
| 60 |
|
| 61 |
return $c->render( status => 200, openapi => $c->objects->to_api($list_id), ); |
| 62 |
} catch { |
| 63 |
$c->unhandled_exception($_); |
| 64 |
}; |
| 65 |
} |
| 66 |
|
| 67 |
=head3 create |
| 68 |
|
| 69 |
Create a virtual shelf |
| 70 |
|
| 71 |
=cut |
| 72 |
|
| 73 |
sub create { |
| 74 |
my $c = shift->openapi->valid_input or return; |
| 75 |
|
| 76 |
return try { |
| 77 |
|
| 78 |
my $list = Koha::Virtualshelf->new_from_api( $c->req->json ); |
| 79 |
$list->store->discard_changes; |
| 80 |
$c->res->headers->location( $c->req->url->to_string . '/' . $list->id ); |
| 81 |
return $c->render( |
| 82 |
status => 201, |
| 83 |
openapi => $c->objects->to_api($list), |
| 84 |
); |
| 85 |
} catch { |
| 86 |
$c->unhandled_exception($_); |
| 87 |
}; |
| 88 |
} |
| 89 |
|
| 90 |
=head3 update |
| 91 |
|
| 92 |
Update a virtual shelf |
| 93 |
|
| 94 |
=cut |
| 95 |
|
| 96 |
sub update { |
| 97 |
my $c = shift->openapi->valid_input or return; |
| 98 |
|
| 99 |
my $list = Koha::Virtualshelves->find( $c->param('list_id') ); |
| 100 |
|
| 101 |
return $c->render_resource_not_found("List") |
| 102 |
unless $list; |
| 103 |
|
| 104 |
return try { |
| 105 |
$list->set_from_api( $c->req->json ); |
| 106 |
$list->store(); |
| 107 |
return $c->render( status => 200, openapi => $c->objects->to_api($list), ); |
| 108 |
} catch { |
| 109 |
$c->unhandled_exception($_); |
| 110 |
}; |
| 111 |
} |
| 112 |
|
| 113 |
=head3 delete |
| 114 |
|
| 115 |
Delete a virtual shelf if it exists |
| 116 |
|
| 117 |
=cut |
| 118 |
|
| 119 |
sub delete { |
| 120 |
my $c = shift->openapi->valid_input or return; |
| 121 |
|
| 122 |
my $list = Koha::Virtualshelves->find( $c->param('list_id') ); |
| 123 |
|
| 124 |
return $c->render_resource_not_found("List") |
| 125 |
unless $list; |
| 126 |
|
| 127 |
return try { |
| 128 |
$list->delete; |
| 129 |
return $c->render_resource_deleted; |
| 130 |
} catch { |
| 131 |
$c->unhandled_exception($_); |
| 132 |
}; |
| 133 |
} |
| 134 |
|
| 30 |
=head3 list_public |
135 |
=head3 list_public |
| 31 |
|
136 |
|
| 32 |
=cut |
137 |
=cut |
|
Lines 73-77
sub list_public {
Link Here
|
| 73 |
$c->unhandled_exception($_); |
178 |
$c->unhandled_exception($_); |
| 74 |
}; |
179 |
}; |
| 75 |
} |
180 |
} |
| 76 |
|
|
|
| 77 |
1; |
181 |
1; |