Skip to content

Commit

Permalink
Merge pull request #676 from metacpan/mickey/release_latest_by_author…
Browse files Browse the repository at this point in the history
…_endpoint

Added /release/latest_by_author/PAUSEID
  • Loading branch information
oalders committed Jun 2, 2017
2 parents e02f92c + c83c481 commit b25d1df
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
34 changes: 34 additions & 0 deletions lib/MetaCPAN/Document/Release.pm
Expand Up @@ -285,6 +285,9 @@ use strict;
use warnings;

use Moose;

use MetaCPAN::Util qw( single_valued_arrayref_to_scalar );

extends 'ElasticSearchX::Model::Document::Set';

sub aggregate_status_by_author {
Expand Down Expand Up @@ -664,5 +667,36 @@ sub activity {
return { activity => $line };
}

sub latest_by_author {
my ( $self, $pauseid ) = @_;

my $body = {
query => {
bool => {
must => [
{ term => { author => uc($pauseid) } },
{ term => { status => 'latest' } }
]
}
},
sort =>
[ 'distribution', { 'version_numified' => { reverse => 1 } } ],
fields => [qw(author distribution name status abstract date)],
size => 1000,
};

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 };
}

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

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

__PACKAGE__->meta->make_immutable;
1;

0 comments on commit b25d1df

Please sign in to comment.