You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficcontrol.apache.org by de...@apache.org on 2016/11/04 20:28:02 UTC
[4/6] incubator-trafficcontrol git commit: added _by_name
functionality for testing
added _by_name functionality for testing
Project: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/commit/eec561e1
Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/tree/eec561e1
Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/diff/eec561e1
Branch: refs/heads/master
Commit: eec561e1d94a52c68f5ba708deb2130223d215ce
Parents: 132c40c
Author: Dewayne Richardson <de...@apache.org>
Authored: Wed Nov 2 14:21:27 2016 -0600
Committer: Dewayne Richardson <de...@apache.org>
Committed: Fri Nov 4 14:25:40 2016 -0600
----------------------------------------------------------------------
traffic_ops/app/lib/API/Division.pm | 47 ++++++++++++++++++++++++++++++++
1 file changed, 47 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/eec561e1/traffic_ops/app/lib/API/Division.pm
----------------------------------------------------------------------
diff --git a/traffic_ops/app/lib/API/Division.pm b/traffic_ops/app/lib/API/Division.pm
index c59e345..a7360b7 100644
--- a/traffic_ops/app/lib/API/Division.pm
+++ b/traffic_ops/app/lib/API/Division.pm
@@ -24,6 +24,25 @@ sub index {
$self->success( \@data );
}
+sub index_by_name {
+ my $self = shift;
+ my $name = $self->param('name');
+
+ my $rs_data = $self->db->resultset("Division")->search( { name => $name } );
+ my @data = ();
+ while ( my $row = $rs_data->next ) {
+ push(
+ @data, {
+ "id" => $row->id,
+ "name" => $row->name,
+ "lastUpdated" => $row->last_updated
+ }
+ );
+ }
+ $self->success( \@data );
+}
+
+
sub show {
my $self = shift;
my $id = $self->param('id');
@@ -142,5 +161,33 @@ sub delete {
}
}
+sub delete_by_name {
+ my $self = shift;
+ my $name = $self->param('name');
+
+ if ( !&is_oper($self) ) {
+ return $self->forbidden();
+ }
+
+ my $division = $self->db->resultset('Division')->find( { name => $name } );
+ if ( !defined($division) ) {
+ return $self->not_found();
+ }
+
+ my $regions = $self->db->resultset('Region')->find( { division => $division->id } );
+ if ( defined($regions) ) {
+ return $self->alert("This division is currently used by regions.");
+ }
+
+
+ my $rs = $division->delete();
+ if ($rs) {
+ return $self->success_message("Division deleted.");
+ } else {
+ return $self->alert( "Division delete failed." );
+ }
+}
+
+
1;