Created
May 7, 2015 21:11
-
-
Save sramshey/5edbb7c81d009191f5bf to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Index: trunk/perllib/bepress/Controller/API/SWNG.pm | |
| =================================================================== | |
| diff -u -N -r41878 -r41880 | |
| --- trunk/perllib/bepress/Controller/API/SWNG.pm (.../SWNG.pm) (revision 41878) | |
| +++ trunk/perllib/bepress/Controller/API/SWNG.pm (.../SWNG.pm) (revision 41880) | |
| @@ -15,13 +15,14 @@ | |
| $self->add_routes([ | |
| - [ '/users/', { action => 'get_users' }, { method => [ 'GET' ] } ], | |
| - [ '/users/:userid/', { action => 'get_user' }, { method => [ 'GET' ] } ], | |
| - [ '/profiles/', { action => 'get_profiles'}, { method => [ 'GET' ] } ], | |
| - [ '/profiles/:userid/', { action => 'get_profile'}, { method => [ 'GET' ] } ], | |
| - [ '/userworks/:userid/', { action => 'get_user_works'}, { method => [ 'GET' ] } ], | |
| - [ '/work/:context_key/', { action => 'get_work'}, { method => [ 'GET' ] } ], | |
| - [ '/register_context/:class', { action => 'register_context'}, { method => 'GET' } ], | |
| + [ '/users/', { action => 'get_users' }, { method => [ 'GET' ] } ], | |
| + [ '/users/:userid/', { action => 'get_user' }, { method => [ 'GET' ] } ], | |
| + [ '/profiles/', { action => 'get_profiles' }, { method => [ 'GET' ] } ], | |
| + [ '/profiles/:userid/', { action => 'get_profile' }, { method => [ 'GET' ] } ], | |
| + [ '/searchuser/:userid/', { action => 'search_user_works' }, { method => [ 'GET', 'POST' ] } ], | |
| + [ '/userworks/:userid/', { action => 'get_user_works' }, { method => [ 'GET' ] } ], | |
| + [ '/work/:context_key/', { action => 'get_work' }, { method => [ 'GET' ] } ], | |
| + [ '/register_context/:class', { action => 'register_context' }, { method => 'GET' } ], | |
| ]); | |
| } | |
| @@ -31,7 +32,6 @@ | |
| my $req = $self->req(); | |
| - | |
| my $afterid = scalar $req->param('after') || 0; | |
| my $count = scalar $req->param('count') || 0; | |
| my $with_profiles = scalar $req->param('with_profiles') || 0; | |
| @@ -170,4 +170,36 @@ | |
| return $res; | |
| } | |
| + | |
| +sub search_user_works { | |
| + my ($self, $args) = @_; | |
| + | |
| + my $data; | |
| + eval { | |
| + $data = $self->bepress::API::SWNG::search_works_for_user($args->{userid}); | |
| + }; | |
| + if ($@) { | |
| + if ($@->isa("bepress::Exception")) { | |
| + $data = $@->{error}; | |
| + } else { | |
| + $data = $@; | |
| + } | |
| + my $res = $self->new_response(500); | |
| + $res->body(encode_json($data)); | |
| + return $res; | |
| + } | |
| + | |
| + if (!$data || $data eq 'not_found') { | |
| + my $res = $self->new_response(404); | |
| + $res->body(encode_json($data)); | |
| + return $res; | |
| + } | |
| + | |
| + my $res = $self->new_response(200); | |
| + $res->content_type('application/json'); | |
| + $res->body(encode_json($data)); | |
| + | |
| + return $res; | |
| +} | |
| + | |
| 1; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment