LibreCat/LibreCat

View on GitHub
lib/LibreCat/App/Search/Route/project.pm

Summary

Maintainability
Test Coverage
package LibreCat::App::Search::Route::project;

=head1 NAME

LibreCat::App::Search::Route::project - handling routes for project pages.

=cut

use Catmandu::Sane;
use Dancer qw/:syntax/;
use LibreCat::App::Helper;
use LibreCat qw(searcher);
use LibreCat::CQL::Util qw(:escape);

=head2 GET /project/:id

Project splash page for :id.

=cut

get qr{/project/([a-zA-Z0-9].*)} => sub {
    my ($id) = splat;
    my $proj = h->project->get($id);

    my $pub = searcher->search('publication',
        {cql => ["project=".cql_escape($id), "status=public"], limit => 100});
    $proj->{project_publication} = $pub if $pub->{total} > 0;

    template 'project/record', $proj;
};

=head2 GET /project

Project page with alphabetical browsing.

=cut

get '/project' => sub {
    my $c             = params("query")->{browse} // 'a';
    my %search_params = (
        query        => {prefix => {'name.exact' => lc($c)}},
        sru_sortkeys => "name,,1",
        limit        => 1000
    );

    h->log->debug(
        "executing project->native_search: " . to_dumper(\%search_params));

    my $hits = searcher->native_search('project', \%search_params);

    template 'project/list', $hits;
};

1;