Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Added /release/all_by_author/PAUSEID endpoint
This new endpoint will be used to replace the query sent from
WEB.
  • Loading branch information
mickeyn committed Jun 3, 2017
1 parent 15547fe commit fd75f41
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
29 changes: 29 additions & 0 deletions lib/MetaCPAN/Document/Release.pm
Expand Up @@ -698,5 +698,34 @@ sub latest_by_author {
return { took => $ret->{took}, releases => $data };
}

sub all_by_author {
my ( $self, $author, $size, $page ) = @_;
$size //= 100;
$page //= 1;

my $body = {
query => { term => { author => uc($author) } },
sort => [ { date => 'desc' } ],
fields => [qw(author distribution name status abstract date)],
size => $size,
from => ( $page - 1 ) * $size,
};
my $ret = $self->es->search(
index => $self->index->name,
type => 'release',
body => $body,
);
return unless $ret->{hits}{total};

my $data = [ map { $_->{fields} } @{ $ret->{hits}{hits} } ];
single_valued_arrayref_to_scalar($data);

return {
took => $ret->{took},
releases => $data,
total => $ret->{hits}{total}
};
}

__PACKAGE__->meta->make_immutable;
1;
8 changes: 8 additions & 0 deletions lib/MetaCPAN/Server/Controller/Release.pm
Expand Up @@ -82,5 +82,13 @@ sub latest_by_author : Path('latest_by_author') : Args(1) {
$c->stash($data);
}

sub all_by_author : Path('all_by_author') : Args(1) {
my ( $self, $c, $pauseid ) = @_;
my @params = @{ $c->req->params }{qw< page page_size >};
my $data = $self->model($c)->raw->all_by_author( $pauseid, @params );
return unless $data;
$c->stash($data);
}

__PACKAGE__->meta->make_immutable;
1;

0 comments on commit fd75f41

Please sign in to comment.