Skip to content

Commit

Permalink
Added /release/by_author_and_name/PAUSEID/RELNAME API endpoint
Browse files Browse the repository at this point in the history
This new endpoint will be used to replace sent query from WEB.
  • Loading branch information
mickeyn committed Jun 23, 2017
1 parent 0795374 commit 03afd2a
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
31 changes: 31 additions & 0 deletions lib/MetaCPAN/Document/Release.pm
Expand Up @@ -612,6 +612,37 @@ sub activity {
return { activity => $line };
}

sub by_author_and_name {
my ( $self, $author, $release ) = @_;

my $body = {
query => {
bool => {
must => [
{ term => { 'name' => $release } },
{ term => { author => uc($author) } }
]
}
}
};

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 {
took => $ret->{took},
releases => $data,
total => $ret->{hits}{total}
};
}

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

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

sub by_author_and_name : Path('by_author_and_name') : Args(2) {
my ( $self, $c, $author, $name ) = @_;
my $data = $self->model($c)->raw->by_author_and_name( $author, $name );
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 03afd2a

Please sign in to comment.