Skip to content

Commit

Permalink
Added /dir/PATH endpoint
Browse files Browse the repository at this point in the history
This new endpoint will be used to replace the query sent from
WEB.
  • Loading branch information
mickeyn committed Jun 2, 2017
1 parent e02f92c commit 5ec6111
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
36 changes: 36 additions & 0 deletions lib/MetaCPAN/Document/File/Set.pm
Expand Up @@ -562,5 +562,41 @@ sub autocomplete_using_suggester {
};
}

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

my $body = {
query => {
bool => {
must => [
{ term => { 'level' => scalar @path } },
{ term => { 'author' => $author } },
{ term => { 'release' => $release } },
{
prefix => {
'path' => join( q{/}, @path, q{} )
}
},
]
},
},
size => 999,
fields => [
qw(name stat.mtime path stat.size directory slop documentation mime)
],
};

my $data = $self->es->search(
{
index => $self->index->name,
type => 'file',
body => $body,
}
);
return unless $data->{hits}{total};

return { dir => $data->{hits}{hits} };
}

__PACKAGE__->meta->make_immutable;
1;
7 changes: 7 additions & 0 deletions lib/MetaCPAN/Server/Controller/File.pm
Expand Up @@ -49,4 +49,11 @@ sub find : Path('') {
} or $c->detach( '/not_found', [$@] );
}

sub dir : Path('dir') {
my ( $self, $c, $author, $release, @path ) = @_;
my $data = $self->model($c)->dir(@path);
return unless $data;
$c->stash($data);
}

1;

0 comments on commit 5ec6111

Please sign in to comment.