moves fetching parameters by profile back into Parameter.pm (my bad) and 
switches ProfileParameter#index back to just a straight fetch from the database 
with no profile filter (again, my bad)


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

Branch: refs/heads/psql
Commit: cba1efece4525435816338c3830d97a096c575a7
Parents: 96c99a8
Author: Jeremy Mitchell <mitchell...@gmail.com>
Authored: Thu Oct 13 21:53:57 2016 -0600
Committer: Jeremy Mitchell <mitchell...@gmail.com>
Committed: Thu Oct 13 21:53:57 2016 -0600

----------------------------------------------------------------------
 traffic_ops/app/lib/API/Parameter.pm        | 33 ++++++++++++++++++++++++
 traffic_ops/app/lib/API/ProfileParameter.pm | 29 ++++++---------------
 traffic_ops/app/lib/TrafficOpsRoutes.pm     |  4 +--
 3 files changed, 43 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/cba1efec/traffic_ops/app/lib/API/Parameter.pm
----------------------------------------------------------------------
diff --git a/traffic_ops/app/lib/API/Parameter.pm 
b/traffic_ops/app/lib/API/Parameter.pm
index 739b7af..216c09b 100644
--- a/traffic_ops/app/lib/API/Parameter.pm
+++ b/traffic_ops/app/lib/API/Parameter.pm
@@ -49,6 +49,39 @@ sub index {
        $self->success( \@data );
 }
 
+sub get_profile_params {
+       my $self         = shift;
+       my $profile_id   = $self->param('id');
+       my $profile_name = $self->param('name');
+
+       my %criteria;
+       if ( defined $profile_id ) {
+               $criteria{'profile.id'} = $profile_id;
+       } elsif ( defined $profile_name ) {
+               $criteria{'profile.name'} = $profile_name;
+       } else {
+        return $self->alert("Profile ID or Name is required");
+    }
+
+       my $rs_data = $self->db->resultset("ProfileParameter")->search( 
\%criteria, { prefetch => [ 'parameter', 'profile' ] } );
+       my @data = ();
+       while ( my $row = $rs_data->next ) {
+               my $value = $row->parameter->value;
+               &UI::Parameter::conceal_secure_parameter_value( $self, 
$row->parameter->secure, \$value );
+               push(
+                       @data, {
+                               "name"        => $row->parameter->name,
+                               "id"          => $row->parameter->id,
+                               "configFile"  => $row->parameter->config_file,
+                               "value"       => $value,
+                               "secure"      => \$row->parameter->secure,
+                               "lastUpdated" => $row->parameter->last_updated
+                       }
+               );
+       }
+       $self->success( \@data );
+}
+
 sub create {
     my $self = shift;
     my $params = $self->req->json;

http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/cba1efec/traffic_ops/app/lib/API/ProfileParameter.pm
----------------------------------------------------------------------
diff --git a/traffic_ops/app/lib/API/ProfileParameter.pm 
b/traffic_ops/app/lib/API/ProfileParameter.pm
index a42d6cb..2495c3f 100644
--- a/traffic_ops/app/lib/API/ProfileParameter.pm
+++ b/traffic_ops/app/lib/API/ProfileParameter.pm
@@ -24,30 +24,17 @@ use Data::Dumper;
 
 # Read
 sub index {
-       my $self         = shift;
-       my $profile_id   = $self->param('id');
-       my $profile_name = $self->param('name');
-
-       my %criteria;
-       if ( defined $profile_id ) {
-               $criteria{'profile.id'} = $profile_id;
-       } elsif ( defined $profile_name ) {
-               $criteria{'profile.name'} = $profile_name;
-       }
-
-       my $rs_data = $self->db->resultset("ProfileParameter")->search( 
\%criteria, { prefetch => [ 'parameter', 'profile' ] } );
-       my @data = ();
+       my $self = shift;
+       my @data;
+       my $orderby = "profile";
+       $orderby = $self->param('orderby') if ( defined $self->param('orderby') 
);
+       my $rs_data = $self->db->resultset("ProfileParameter")->search( undef, 
{ order_by => $orderby } );
        while ( my $row = $rs_data->next ) {
-               my $value = $row->parameter->value;
-               &UI::Parameter::conceal_secure_parameter_value( $self, 
$row->parameter->secure, \$value );
                push(
                        @data, {
-                               "name"        => $row->parameter->name,
-                               "id"          => $row->parameter->id,
-                               "configFile"  => $row->parameter->config_file,
-                               "value"       => $value,
-                               "secure"      => \$row->parameter->secure,
-                               "lastUpdated" => $row->parameter->last_updated
+                               "profile"     => $row->profile->name,
+                               "parameter"   => $row->parameter->id,
+                               "lastUpdated" => $row->last_updated,
                        }
                );
        }

http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/cba1efec/traffic_ops/app/lib/TrafficOpsRoutes.pm
----------------------------------------------------------------------
diff --git a/traffic_ops/app/lib/TrafficOpsRoutes.pm 
b/traffic_ops/app/lib/TrafficOpsRoutes.pm
index 7febe79..5f7d34d 100644
--- a/traffic_ops/app/lib/TrafficOpsRoutes.pm
+++ b/traffic_ops/app/lib/TrafficOpsRoutes.pm
@@ -576,8 +576,8 @@ sub api_routes {
        $r->post("/api/$version/parameters/validate")->over( authenticated => 1 
)->to( 'Parameter#validate', namespace => $namespace );
 
        # parameters for a profile
-       $r->get( "/api/$version/profiles/:id/parameters" => [ id => qr/\d+/ ] 
)->over( authenticated => 1 )->to( 'ProfileParameter#index', namespace => 
$namespace );
-       $r->get("/api/$version/profiles/name/:name/parameters")->over( 
authenticated => 1 )->to( 'ProfileParameter#index', namespace => $namespace );
+       $r->get( "/api/$version/profiles/:id/parameters" => [ id => qr/\d+/ ] 
)->over( authenticated => 1 )->to( 'Parameter#get_profile_params', namespace => 
$namespace );
+       $r->get("/api/$version/profiles/name/:name/parameters")->over( 
authenticated => 1 )->to( 'Parameter#get_profile_params', namespace => 
$namespace );
        $r->post("/api/$version/profiles/name/:name/parameters")->over( 
authenticated => 1 )
                ->to( 'ProfileParameter#create_param_for_profile_name', 
namespace => $namespace );
        $r->post("/api/$version/profiles/:id/parameters")->over( authenticated 
=> 1 )

Reply via email to