Skip to content

Commit

Permalink
Merge pull request #699 from metacpan/mickey/release_by_author_endpoint
Browse files Browse the repository at this point in the history
Added /release/by_author/PAUSEID endpoint
  • Loading branch information
oalders committed Jun 28, 2017
2 parents 948ef6f + f25d38f commit e7e9845
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
38 changes: 38 additions & 0 deletions lib/MetaCPAN/Document/Release.pm
Expand Up @@ -643,6 +643,44 @@ sub by_author_and_name {
};
}

sub by_author {
my ( $self, $pauseid, $size ) = @_;
$size //= 1000;

my $body = {
query => {
bool => {
must => [
{ terms => { status => [qw< cpan latest >] } },
( $pauseid ? { term => { author => $pauseid } } : () ),
],
}
},
sort =>
[ 'distribution', { 'version_numified' => { reverse => 1 } } ],
_source => [
qw( abstract author authorized date distribution license metadata.version resources.repository status tests )
],
size => $size,
};

my $ret = $self->es->search(
index => $self->index->name,
type => 'release',
body => $body,
);
return unless $ret->{hits}{total};

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

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

sub latest_by_distribution {
my ( $self, $distribution ) = @_;

Expand Down
8 changes: 8 additions & 0 deletions lib/MetaCPAN/Server/Controller/Release.pm
Expand Up @@ -89,6 +89,14 @@ sub by_author_and_name : Path('by_author_and_name') : Args(2) {
$c->stash($data);
}

sub by_author : Path('by_author') : Args(1) {
my ( $self, $c, $pauseid ) = @_;
my $size = $c->req->param('size');
my $data = $self->model($c)->raw->by_author( $pauseid, $size );
return unless $data;
$c->stash($data);
}

sub latest_by_distribution : Path('latest_by_distribution') : Args(1) {
my ( $self, $c, $dist ) = @_;
my $data = $self->model($c)->raw->latest_by_distribution($dist);
Expand Down

0 comments on commit e7e9845

Please sign in to comment.