Skip to content

Commit

Permalink
added new /favorite/recent endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
mickeyn committed Nov 25, 2016
1 parent 7e9e476 commit a08f4f9
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
18 changes: 17 additions & 1 deletion lib/MetaCPAN/Document/Favorite.pm
Expand Up @@ -33,7 +33,6 @@ has date => (

__PACKAGE__->meta->make_immutable;


package MetaCPAN::Document::Favorite::Set;

use MetaCPAN::Moose;
Expand Down Expand Up @@ -61,5 +60,22 @@ sub by_distribution {
);
}

sub recent {
my ( $self, $req ) = @_;
my ( $size, $page ) = @{ $req->parameters }{qw< size page >};
$size ||= 20;
$page ||= 1;
return $self->es->search(
index => $self->index->name,
type => 'favorite',
body => {
query => { match_all => {} },
size => $size,
from => ( $page - 1 ) * $size,
sort => [ { 'date' => { order => 'desc' } } ],
}
);
}

__PACKAGE__->meta->make_immutable;
1;
8 changes: 8 additions & 0 deletions lib/MetaCPAN/Server/Controller/Favorite.pm
Expand Up @@ -53,5 +53,13 @@ sub plusser_by_user : Path('plusser_by_user') : Args(0) {
$c->stash($data);
}

# endpoint: /favorite/recent
# optional: [&fields=<field>][&sort=<sort_key>][&size=N][&page=N]
sub recent : Path('recent') : Args(0) {
my ( $self, $c ) = @_;
my $data = $self->model($c)->raw->recent( $c->req );
$c->stash($data);
}

__PACKAGE__->meta->make_immutable;
1;

0 comments on commit a08f4f9

Please sign in to comment.