From ccfa4758737db9aae08dd0b3b525423375b7b284 Mon Sep 17 00:00:00 2001 From: Robert Buels Date: Sun, 28 Nov 2010 13:06:57 -0800 Subject: [PATCH] add controller with a web service for serving sitefeature xrefs --- lib/SGN/Controller/SiteFeatures.pm | 69 ++++++++++++++++++++++++++++++++++++++ t/SGN/Controller/SiteFeatures.t | 10 ++++++ 2 files changed, 79 insertions(+) create mode 100644 lib/SGN/Controller/SiteFeatures.pm create mode 100644 t/SGN/Controller/SiteFeatures.t diff --git a/lib/SGN/Controller/SiteFeatures.pm b/lib/SGN/Controller/SiteFeatures.pm new file mode 100644 index 000000000..1580a7de0 --- /dev/null +++ b/lib/SGN/Controller/SiteFeatures.pm @@ -0,0 +1,69 @@ +package SGN::Controller::SiteFeatures; +use Moose; +use namespace::autoclean; + +use SGN::View::Mason::CrossReference 'resolve_xref_component'; + +BEGIN {extends 'Catalyst::Controller::REST'; } + +__PACKAGE__->config( + default => 'text/html', + stash_key => 'rest', + map => { + 'text/html' => [ 'View', 'BareMason' ], + }, + ); + +=head1 NAME + +SGN::Controller::SiteFeatures - Catalyst Controller + +=head1 DESCRIPTION + +Catalyst controller for web services involving site features and +xrefs. + +=head1 PUBLIC ACTIONS + +=head2 feature_xrefs + +Public path: /api/v1/feature_xrefs + +Web service interface to C<$c-Efeature_xrefs>. + +=cut + +sub feature_xrefs :Path('/api/v1/feature_xrefs') :Args(0) { + my ( $self, $c ) = @_; + + no warnings 'uninitialized'; + + my $type = $c->req->param('render_type') || 'link'; + + my $args = {}; + if( my @exclude = split /,/, $c->req->param('exclude') ) { + $args->{exclude} = \@exclude; + } + + my $xrefs = [ $c->feature_xrefs( $c->req->param('q'), $args ) ]; + $c->stash( + template => "/sitefeatures/mixed/xref_set/$type.mas", + + xrefs => $xrefs, + rest => $xrefs, + ); +} + +=head1 AUTHOR + +Robert Buels + +=head1 LICENSE + +This library is free software. You can redistribute it and/or modify +it under the same terms as Perl itself. + +=cut + +__PACKAGE__->meta->make_immutable; + diff --git a/t/SGN/Controller/SiteFeatures.t b/t/SGN/Controller/SiteFeatures.t new file mode 100644 index 000000000..473d84e64 --- /dev/null +++ b/t/SGN/Controller/SiteFeatures.t @@ -0,0 +1,10 @@ +use strict; +use warnings; +use Test::More; + +use lib 't/lib'; +use SGN::Test 'request'; +BEGIN { use_ok 'SGN::Controller::SiteFeatures' } + +ok( request('/api/v1/feature_xrefs?q=Solyc05g005010')->is_success, 'feature_xrefs requestssss should succeed' ); +done_testing(); -- 2.11.4.GIT