Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #636 from metacpan/mickey/release_files_lookup_end…
…point

Added an endpoint for looking up files for a release
  • Loading branch information
oalders committed May 12, 2017
2 parents 887b530 + 4e04b40 commit f1bfbb0
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
29 changes: 29 additions & 0 deletions lib/MetaCPAN/Document/Release.pm
Expand Up @@ -510,5 +510,34 @@ sub get_contributors {
return { contributors => \@contribs };
}

sub get_files {
my ( $self, $release, $files ) = @_;

my $query = +{
query => {
bool => {
must => [
{ term => { release => $release } },
{ terms => { name => $files } }
],
}
}
};

my $ret = $self->es->search(
index => $self->index->name,
type => 'file',
body => {
query => $query,
size => 999,
_source => [qw< name path >],
}
);

return {} unless @{ $ret->{hits}{hits} };

return { files => [ map { $_->{_source} } @{ $ret->{hits}{hits} } ] };
}

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

sub files : Path('files') : Args(1) {
my ( $self, $c, $name ) = @_;
my $files = $c->req->params->{files};
return unless $files;
my @files = split /,/, $files;
my $data = $self->model($c)->raw->get_files( $name, \@files );
$c->stash($data);
}

__PACKAGE__->meta->make_immutable;
1;

0 comments on commit f1bfbb0

Please sign in to comment.