<commit_before>package API::Region;
#
# Copyright 2015 Comcast Cable Communications Management, LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
#
#

use UI::Utils;

use Mojo::Base 'Mojolicious::Controller';
use Data::Dumper;
use JSON;
use MojoPlugins::Response;

my $finfo = __FILE__ . ":";

sub index {
	my $self = shift;
	my @data;
	my $orderby = $self->param('orderby') || "name";
	my $rs_data = $self->db->resultset("Region")->search( undef, { prefetch => ['division'], order_by => 'me.' . $orderby } );
	while ( my $row = $rs_data->next ) {
		push(
			@data, {
				"id"       => $row->id,
				"name"     => $row->division->name,
				"division" => $row->division->id,
				"divisionName" => $row->name
			}
		);
	}
	$self->success( \@data );
}

sub show {
	my $self = shift;
	my $id   = $self->param('id');

	my $rs_data = $self->db->resultset("Region")->search( { 'me.id' => $id }, { prefetch => ['division'] } );
	my @data = ();
	while ( my $row = $rs_data->next ) {
		push(
			@data, {
				"id"       => $row->id,
				"name"     => $row->division->name,
				"division" => $row->division->id,
				"divisionName" => $row->name
			}
		);
	}
	$self->success( \@data );
}

sub create {
	my $self          = shift;
	my $division_name = $self->param('division_name');
	my $params        = $self->req->json;
	if ( !defined($params) ) {
		return $self->alert("parameters must be in JSON format,  please check!");
	}
	if ( !&is_oper($self) ) {
		return $self->alert("You must be an ADMIN or OPER to perform this operation!");
	}

	my $existing_region = $self->db->resultset('Region')->search( { name => $params->{name} } )->get_column('name')->single();
	if ( defined($existing_region) ) {
		return $self->alert( "region[" . $params->{name} . "] already exists." );
	}

	my $divsion_id = $self->db->resultset('Division')->search( { name => $division_name } )->get_column('id')->single();
	if ( !defined($divsion_id) ) {
		return $self->alert( "division[" . $division_name . "] does not exist." );
	}<commit_msg>fixes reversed properties<commit_after>package API::Region;
#
# Copyright 2015 Comcast Cable Communications Management, LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
#
#

use UI::Utils;

use Mojo::Base 'Mojolicious::Controller';
use Data::Dumper;
use JSON;
use MojoPlugins::Response;

my $finfo = __FILE__ . ":";

sub index {
	my $self = shift;
	my @data;
	my $orderby = $self->param('orderby') || "name";
	my $rs_data = $self->db->resultset("Region")->search( undef, { prefetch => ['division'], order_by => 'me.' . $orderby } );
	while ( my $row = $rs_data->next ) {
		push(
			@data, {
				"id"       => $row->id,
				"name"     => $row->name,
				"division" => $row->division->id,
				"divisionName" => $row->division->name
			}
		);
	}
	$self->success( \@data );
}

sub show {
	my $self = shift;
	my $id   = $self->param('id');

	my $rs_data = $self->db->resultset("Region")->search( { 'me.id' => $id }, { prefetch => ['division'] } );
	my @data = ();
	while ( my $row = $rs_data->next ) {
		push(
			@data, {
				"id"       => $row->id,
				"name"     => $row->name,
				"division" => $row->division->id,
				"divisionName" => $row->division->name
			}
		);
	}
	$self->success( \@data );
}

sub create {
	my $self          = shift;
	my $division_name = $self->param('division_name');
	my $params        = $self->req->json;
	if ( !defined($params) ) {
		return $self->alert("parameters must be in JSON format,  please check!");
	}
	if ( !&is_oper($self) ) {
		return $self->alert("You must be an ADMIN or OPER to perform this operation!");
	}

	my $existing_region = $self->db->resultset('Region')->search( { name => $params->{name} } )->get_column('name')->single();
	if ( defined($existing_region) ) {
		return $self->alert( "region[" . $params->{name} . "] already exists." );
	}

	my $divsion_id = $self->db->resultset('Division')->search( { name => $division_name } )->get_column('id')->single();
	if ( !defined($divsion_id) ) {
		return $self->alert( "division[" . $division_name . "] does not exist." );
	}
{'fraction_non_alphanumeric': 0.1875248311481923, 'fraction_numerical': 0.0031783869686134287, 'mean_word_length': 3.5814376706096454, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 117, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '7537577', 'n_tokens_mistral': 1835, 'n_tokens_neox': 1700, 'n_words': 472}