Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Added /release/versions/DIST endpoint
This new endpoint will be used to replace the query sent from
WEB.
  • Loading branch information
mickeyn committed Jun 4, 2017
1 parent aca9e3e commit 6c3c9cc
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 6c3c9cc

Please sign in to comment.