From 5a88c283d577c9b3d660fc617cb113ac5cb0d42d Mon Sep 17 00:00:00 2001 From: Finn Date: Mon, 15 Jan 2018 14:18:27 +0000 Subject: [PATCH] added category API --- lib/Pear/LocalLoop.pm | 1 + lib/Pear/LocalLoop/Controller/Api/Upload.pm | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/lib/Pear/LocalLoop.pm b/lib/Pear/LocalLoop.pm index 0146d63..32814cf 100644 --- a/lib/Pear/LocalLoop.pm +++ b/lib/Pear/LocalLoop.pm @@ -144,6 +144,7 @@ sub startup { }); $api->post('/upload')->to('api-upload#post_upload'); $api->post('/search')->to('api-upload#post_search'); + $api->post('/search/category')->to('api-upload#post_category'); $api->post('/user')->to('api-user#post_account'); $api->post('/user/account')->to('api-user#post_account_update'); $api->post('/user-history')->to('api-user#post_user_history'); diff --git a/lib/Pear/LocalLoop/Controller/Api/Upload.pm b/lib/Pear/LocalLoop/Controller/Api/Upload.pm index 3783d7f..26cc34d 100644 --- a/lib/Pear/LocalLoop/Controller/Api/Upload.pm +++ b/lib/Pear/LocalLoop/Controller/Api/Upload.pm @@ -209,6 +209,20 @@ sub post_upload { }); } +sub post_category { + my $c = shift; + my $self = $c; + + my $category_rs = $c->schema->resultset('Category'); + $category_rs->result_class('DBIx::Class::ResultClass::HashRefInflator'); + $categories => [ $category_rs->all ] ); + + return $self->render( json => { + success => Mojo::JSON->true, + categories => $categories, + }); +} + # TODO Limit search results, possibly paginate them? # TODO Search by location as well sub post_search {