Skip to content

Instantly share code, notes, and snippets.

@rkitover
Created December 10, 2012 18:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rkitover/4252236 to your computer and use it in GitHub Desktop.
Save rkitover/4252236 to your computer and use it in GitHub Desktop.
#!/usr/bin/env perl
use FindBin '$Bin';
use lib "$Bin/perl";
use EMS::DBUtils;
use EMS::Authorization;
use Mojolicious::Lite;
my ($dbh, $user);
under '/' => sub {
my $self = shift;
if ((not $dbh) || (not $dbh->ping)) {
$dbh = $EMS::DBUtils::dbh = EMS::DBUtils::dbConnect();
}
# $user = EMS::Authorization->new->verifyAuth($self->param('sessionId'), 1, {})
# or $self->render_text('You must be logged in to use the API.');
};
get '/work_order_category/:cat_type' => [cat_type => ['', 'r', 'p']] => sub {
my $self = shift;
my $categories = $dbh->prepare_cached(<<'EOF');
SELECT id, category_name
FROM fsm_wo_category
WHERE status = 'A' AND type = IFNULL(?, type)
ORDER BY category_name ASC
EOF
my %data = map @$_, $dbh->selectall_arrayref($categories, {}, $self->param('cat_type'));
$self->respond_to(
json => { json => \%data }
);
};
get '/work_order_type/:cat' => [cat => qr/^\d+\z/] => sub {
my $self = shift;
my $wo_types = $dbh->prepare_cached(<<'EOF');
SELECT wt.id id, wt.name name
FROM category_workorder_mapping cm
JOIN fsm_wo_type wt
ON cm.workorder_type_id = wt.id
WHERE cm.category_id = ? AND wt.system = 'n'
ORDER BY wt.name ASC
EOF
my %data = map @$_, $dbh->selectall_arrayref($wo_types, {}, $self->param('cat'));
$self->respond_to(
json => { json => \%data }
);
};
app->start;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment