provides the ability to filter asns by cachegroup id

Project: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/repo
Commit: 
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/commit/9059556a
Tree: 
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/tree/9059556a
Diff: 
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/diff/9059556a

Branch: refs/heads/master
Commit: 9059556ac85cb4f538f0442b3112c4d4337a1c1b
Parents: c9e1282
Author: Jeremy Mitchell <mitchell...@gmail.com>
Authored: Wed Dec 28 14:14:09 2016 -0700
Committer: Jeremy Mitchell <mitchell...@gmail.com>
Committed: Wed Dec 28 14:14:09 2016 -0700

----------------------------------------------------------------------
 docs/source/development/traffic_ops_api/v12/asn.rst |  8 ++++++++
 traffic_ops/app/lib/API/Asn.pm                      | 11 +++++++++--
 2 files changed, 17 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/9059556a/docs/source/development/traffic_ops_api/v12/asn.rst
----------------------------------------------------------------------
diff --git a/docs/source/development/traffic_ops_api/v12/asn.rst 
b/docs/source/development/traffic_ops_api/v12/asn.rst
index d3ae765..0b56996 100644
--- a/docs/source/development/traffic_ops_api/v12/asn.rst
+++ b/docs/source/development/traffic_ops_api/v12/asn.rst
@@ -30,6 +30,14 @@ ASN
 
   Role(s) Required: None
 
+  **Request Query Parameters**
+
+  
+---------------------+----------+---------------------------------------------+
+  |   Name              | Required |                Description                
  |
+  
+=====================+==========+=============================================+
+  |   ``cachegroupId``  |    no    | Filter ASNs by cache group ID             
  |
+  
+---------------------+----------+---------------------------------------------+
+
   **Response Properties**
 
   
+------------------+--------+-------------------------------------------------------------------------+

http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/9059556a/traffic_ops/app/lib/API/Asn.pm
----------------------------------------------------------------------
diff --git a/traffic_ops/app/lib/API/Asn.pm b/traffic_ops/app/lib/API/Asn.pm
index 080099a..8557059 100644
--- a/traffic_ops/app/lib/API/Asn.pm
+++ b/traffic_ops/app/lib/API/Asn.pm
@@ -24,10 +24,17 @@ use Data::Dumper;
 
 # Index
 sub index {
-       my $self = shift;
+       my $self    = shift;
+       my $cg_id   = $self->param('cachegroupId');
+
+       my %criteria;
+       if ( defined $cg_id ) {
+               $criteria{'cachegroup.id'} = $cg_id;
+       }
+
        my @data;
        my $orderby = $self->param('orderby') || "asn";
-       my $rs_data = $self->db->resultset("Asn")->search( undef, { prefetch => 
[ { 'cachegroup' => undef } ], order_by => "me." . $orderby } );
+       my $rs_data = $self->db->resultset("Asn")->search( \%criteria, { 
prefetch => [ { 'cachegroup' => undef } ], order_by => "me." . $orderby } );
        while ( my $row = $rs_data->next ) {
                push(
                        @data, {

Reply via email to