<commit_before>package Pakket::Web::Repo;
# ABSTRACT: A web repository app

use Dancer2 'appname' => 'Pakket::Web';
use Dancer2::Plugin::Pakket::ParamTypes;

use Carp qw< croak >;
use Log::Any qw< $log >;
use Pakket::Repository::Spec;
use Pakket::Repository::Parcel;
use Pakket::Repository::Source;

## no critic qw(Modules::RequireExplicitInclusion)

my %repo_types = (
    'spec'   => sub { return Pakket::Repository::Spec->new(@_);   },
    'source' => sub { return Pakket::Repository::Source->new(@_); },
    'parcel' => sub { return Pakket::Repository::Parcel->new(@_); },
);

sub create {
    my ( $class, $args ) = @_;

    my $repo_type    = $args->{'type'}    or croak(q{Missing 'type'});
    my $repo_path    = $args->{'path'}    or croak(q{Missing 'path'});
    my $repo_backend = $args->{'backend'} or croak(q{Missing 'backend'});

    my $repo = $repo_types{$repo_type}->( 'backend' => $repo_backend );

    prefix $repo_path => sub {
        get '/has_object' => with_types [
            [ 'query', 'id', 'Str', 'MissingID' ],
        ] => sub {
            my $id = query_parameters->get('id');

            return encode_json({
                'has_object' => $repo->has_object($id),
            });
        };

        get '/all_object_ids' => sub {
            return encode_json({
                'object_ids' => $repo->all_object_ids,
            });
        };

        get '/all_object_ids_by_name' => with_types [
            [ 'query', 'name',     'Str', 'MissingName' ],
            [ 'query', 'category', 'Str', 'MissingCategory' ],
        ] => sub {
            my $name     = query_parameters->get('name');
            my $category = query_parameters->get('category');
            return encode_json({
                'object_ids' => $repo->all_object_ids_by_name($name, $category),
            });
        };

        prefix '/retrieve' => sub {
            get '/content' => with_types [<commit_msg>Add web endpoint to show version and number of objects in repo<commit_after>package Pakket::Web::Repo;
# ABSTRACT: A web repository app

use Dancer2 'appname' => 'Pakket::Web';
use Dancer2::Plugin::Pakket::ParamTypes;

use Carp qw< croak >;
use Log::Any qw< $log >;
use Pakket::Repository::Spec;
use Pakket::Repository::Parcel;
use Pakket::Repository::Source;

## no critic qw(Modules::RequireExplicitInclusion)

my %repo_types = (
    'spec'   => sub { return Pakket::Repository::Spec->new(@_);   },
    'source' => sub { return Pakket::Repository::Source->new(@_); },
    'parcel' => sub { return Pakket::Repository::Parcel->new(@_); },
);

sub create {
    my ( $class, $args ) = @_;

    my $repo_type    = $args->{'type'}    or croak(q{Missing 'type'});
    my $repo_path    = $args->{'path'}    or croak(q{Missing 'path'});
    my $repo_backend = $args->{'backend'} or croak(q{Missing 'backend'});

    my $repo = $repo_types{$repo_type}->( 'backend' => $repo_backend );

    prefix $repo_path => sub {
        get '/info' => sub {
            return encode_json({
                'version' => $Pakket::Web::Repo::VERSION,
                'objects' => scalar @{$repo->all_object_ids},
            });
        };

        get '/has_object' => with_types [
            [ 'query', 'id', 'Str', 'MissingID' ],
        ] => sub {
            my $id = query_parameters->get('id');

            return encode_json({
                'has_object' => $repo->has_object($id),
            });
        };

        get '/all_object_ids' => sub {
            return encode_json({
                'object_ids' => $repo->all_object_ids,
            });
        };

        get '/all_object_ids_by_name' => with_types [
            [ 'query', 'name',     'Str', 'MissingName' ],
            [ 'query', 'category', 'Str', 'MissingCategory' ],
        ] => sub {
            my $name     = query_parameters->get('name');
            my $category = query_parameters->get('category');
            return encode_json({
                'object_ids' => $repo->all_object_ids_by_name($name, $category),
            });
        };

        prefix '/retrieve' => sub {
            get '/content' => with_types [
{'fraction_non_alphanumeric': 0.17819859189123574, 'fraction_numerical': 0.0009711094925952901, 'mean_word_length': 2.396537510305029, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 69, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2449010', 'n_tokens_mistral': 1305, 'n_tokens_neox': 1279, 'n_words': 273}