<commit_before>package CoGe::Services::Data::Organism;

use Mojo::Base 'Mojolicious::Controller';
#use IO::Compress::Gzip 'gzip';
use CoGeX;
use CoGe::Accessory::Web;

sub search {
    my $self = shift;
    my $search_term = $self->stash('term');
    my $key = $self->param("apiKey");

    # Validate input
    if (!$search_term or length($search_term) < 3) {
        $self->render(json => { status => Mojo::JSON->false, error => 'Too many search results'});
        return;
    }

    # Connect to the database
    my ( $db, $user, $conf ) = CoGe::Accessory::Web->init(ticket => $key);

    # Search organisms
    my $search_term2 = '%' . $search_term . '%';
    my @organisms = $db->resultset("Organism")->search(
        \[
            'organism_id = ? OR name LIKE ? OR description LIKE ?',
            [ 'organism_id', $search_term  ],
            [ 'name',        $search_term2 ],
            [ 'description', $search_term2 ]
        ]
    );

    # Format response
    my @result = map {
        {
            id => $_->id,
            name => $_->name,
            description => $_->description
        }
    } @organisms;
    $self->render(json => { organisms => \@result });
}

sub fetch {
    my $self = shift;
    my $id = int($self->stash('id'));

    if ($id < 1) {
        $self->render(json => { status => Mojo::JSON->false, error => 'Not a valid id'});
        return;
    }

    # Connect to the database
    my ( $db, $user, $conf ) = CoGe::Accessory::Web->init();

    my $organism = $db->resultset("Organism")->find($id);

    unless (defined $organism) {
        $self->render(json => { status => Mojo::JSON->false, error => 'The organism could not be found'});
        return;
    }

    $self->render(json => {
        id => $id,
        name => $organism->name,
        description => $organism->description,
    });
}

sub add {
    my $self = shift;<commit_msg>update error message<commit_after>package CoGe::Services::Data::Organism;

use Mojo::Base 'Mojolicious::Controller';
#use IO::Compress::Gzip 'gzip';
use CoGeX;
use CoGe::Accessory::Web;

sub search {
    my $self = shift;
    my $search_term = $self->stash('term');
    my $key = $self->param("apiKey");

    # Validate input
    if (!$search_term or length($search_term) < 3) {
        $self->render(json => { status => Mojo::JSON->false, error => 'Too many search results'});
        return;
    }

    # Connect to the database
    my ( $db, $user, $conf ) = CoGe::Accessory::Web->init(ticket => $key);

    # Search organisms
    my $search_term2 = '%' . $search_term . '%';
    my @organisms = $db->resultset("Organism")->search(
        \[
            'organism_id = ? OR name LIKE ? OR description LIKE ?',
            [ 'organism_id', $search_term  ],
            [ 'name',        $search_term2 ],
            [ 'description', $search_term2 ]
        ]
    );

    # Format response
    my @result = map {
        {
            id => $_->id,
            name => $_->name,
            description => $_->description
        }
    } @organisms;
    $self->render(json => { organisms => \@result });
}

sub fetch {
    my $self = shift;
    my $id = int($self->stash('id'));

    if ($id < 1) {
        $self->render(json => { status => Mojo::JSON->false, error => 'Not a valid id'});
        return;
    }

    # Connect to the database
    my ( $db, $user, $conf ) = CoGe::Accessory::Web->init();

    my $organism = $db->resultset("Organism")->find($id);

    unless (defined $organism) {
        $self->render(json => {
            error => { Error => "Item not found"}
        });
        return;
    }

    $self->render(json => {
        id => $id,
        name => $organism->name,
        description => $organism->description,
    });
}

sub add {
    my $self = shift;
{'fraction_non_alphanumeric': 0.1805408271474019, 'fraction_numerical': 0.002651113467656416, 'mean_word_length': 2.252586206896552, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 84, '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': '6954991', 'n_tokens_mistral': 1239, 'n_tokens_neox': 1204, 'n_words': 283}