Skip to content

Commit

Permalink
Merge pull request #666 from metacpan/mickey/author_by_user
Browse files Browse the repository at this point in the history
Improved /author/by_user endpoint
  • Loading branch information
oalders committed May 31, 2017
2 parents 0453191 + 215e5c0 commit be6d0ac
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/MetaCPAN/Document/Author.pm
Expand Up @@ -155,16 +155,19 @@ use warnings;
use Moose;
extends 'ElasticSearchX::Model::Document::Set';

use Ref::Util qw( is_arrayref );

use MetaCPAN::Util qw( single_valued_arrayref_to_scalar );

sub by_user {
my ( $self, $users ) = @_;
$users = [$users] unless is_arrayref($users);

my $authors = $self->es->search(
index => $self->index->name,
type => 'author',
body => {
query => { term => { user => $users } },
query => { terms => { user => $users } },
size => 100,
fields => [qw( user pauseid )],
}
Expand Down
11 changes: 11 additions & 0 deletions lib/MetaCPAN/Server/Controller/Author.pm
Expand Up @@ -61,11 +61,22 @@ sub get : Path('') : Args(1) {
['The requested field(s) could not be found'] );
}

# /author/by_user/USER_ID
sub by_user : Path('by_user') : Args(1) {
my ( $self, $c, $user ) = @_;
my $data = $self->model($c)->raw->by_user($user);
$data or return;
$c->stash($data);
}

# /author/by_user?user=USER_ID1&user=USER_ID2...
sub by_users : Path('by_user') : Args(0) {
my ( $self, $c ) = @_;
my @users = $c->req->param('user');
return unless @users;
my $data = $self->model($c)->raw->by_user( \@users );
$data or return;
$c->stash($data);
}

1;

0 comments on commit be6d0ac

Please sign in to comment.