Skip to content

Commit

Permalink
Merge pull request #681 from metacpan/mickey/release_versions_endpoint
Browse files Browse the repository at this point in the history
Added /release/versions/DIST endpoint
  • Loading branch information
oalders committed Jun 4, 2017
2 parents aca9e3e + 6c3c9cc commit 7609d9b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
23 changes: 23 additions & 0 deletions lib/MetaCPAN/Document/Release.pm
Expand Up @@ -727,5 +727,28 @@ sub all_by_author {
};
}

sub versions {
my ( $self, $dist ) = @_;

my $body = {
query => { term => { distribution => $dist } },
size => 250,
sort => [ { date => 'desc' } ],
fields => [qw( name date author version status maturity authorized )],
};

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 { releases => $data };
}

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

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

__PACKAGE__->meta->make_immutable;
1;

0 comments on commit 7609d9b

Please sign in to comment.