zrhoffman commented on code in PR #7615:
URL: https://github.com/apache/trafficcontrol/pull/7615#discussion_r1273676836


##########
experimental/traffic-portal/src/app/api/testing/topology.service.ts:
##########
@@ -0,0 +1,130 @@
+/*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+import { Injectable } from "@angular/core";
+import {
+       RequestTopology,
+       ResponseTopology,
+       ResponseTopologyNode
+} from "trafficops-types";
+
+/**
+ * TopologyService expose API functionality relating to Topologies.
+ */
+@Injectable()
+export class TopologyService {
+       private readonly topologies: ResponseTopology[] = [
+               {
+                       description: "",
+                       lastUpdated: new Date(),
+                       name: "test",
+                       nodes: [
+                               {
+                                       cachegroup: "Edge",
+                                       parents: [1],
+                               },
+                               {
+                                       cachegroup: "Mid",
+                                       parents: [2],
+                               },
+                               {
+                                       cachegroup: "Origin",
+                                       parents: [],
+                               },
+                       ],
+               }
+       ];
+
+       /**
+        * Gets one or all Topologies from Traffic Ops
+        *
+        * @param name? The integral, unique identifier of a single Topology to 
be
+        * returned
+        * @returns Either a Map of Topology names to full Topology objects, or 
a single Topology, depending on whether `id` was
+        *      passed.
+        * (In the event that `id` is passed but does not match any Topology, 
`null` will be emitted)
+        */
+       public async getTopologies(name?: string): 
Promise<Array<ResponseTopology> | ResponseTopology> {
+               if (name !== undefined) {
+                       const topology = this.topologies.find(t => t.name === 
name);
+                       if (!topology) {
+                               throw new Error(`no such Topology #${name}`);
+                       }
+                       return topology;
+               }
+               return this.topologies;
+       }
+
+       /**
+        * Deletes a Topology.
+        *
+        * @param topology The Topology to be deleted, or just its ID.
+        */
+       public async deleteTopology(topology: ResponseTopology | string): 
Promise<void> {
+               const name = typeof topology === "string" ? topology : 
topology.name;
+               const idx = this.topologies.findIndex(t => t.name === name);
+               if (idx < 0) {
+                       throw new Error(`no such Topology: #${name}`);
+               }
+               this.topologies.splice(idx, 1);
+       }
+
+       /**
+        * Creates a new Topology.
+        *
+        * @param topology The Topology to create.
+        */
+       public async createTopology(topology: RequestTopology): 
Promise<ResponseTopology> {
+               const nodes: ResponseTopologyNode[] = topology.nodes.map(node 
=> {
+                       if (!(node.parents instanceof Array)) {
+                               node.parents = [];
+                       }
+                       const responseNode: ResponseTopologyNode = {
+                               cachegroup: node.cachegroup,
+                               parents: node.parents || [],
+                       };
+                       return responseNode;
+               });
+               const t: ResponseTopology = {
+                       description: topology.description || "",
+                       lastUpdated: new Date(),
+                       name: topology.name,
+                       nodes,
+               };
+               this.topologies.push(t);
+               return t;
+       }
+
+       /**
+        * Replaces an existing Topology with the provided new definition of a
+        * Topology.
+        *
+        * @param topology The full new definition of the Topology being
+        * updated, or just its ID.

Review Comment:
   Changed to `name`, reworded description



##########
experimental/traffic-portal/src/app/api/topology.service.ts:
##########
@@ -0,0 +1,196 @@
+/*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+import { HttpClient } from "@angular/common/http";
+import { Injectable } from "@angular/core";
+import type {
+       RequestTopology,
+       ResponseTopology,
+       ResponseTopologyNode,
+} from "trafficops-types";
+
+import { APIService } from "./base-api.service";
+
+/**
+ * TopTreeNode is used to represent a topology in a format usable as a material
+ * nested tree data source.
+ */
+export interface TopTreeNode {
+       name: string;
+       cachegroup: string;
+       children: Array<TopTreeNode>;
+       parents: Array<this>;
+}
+
+/**
+ * TopologyService exposes API functionality relating to Topologies.
+ */
+@Injectable()
+export class TopologyService extends APIService {
+
+       constructor(http: HttpClient) {
+               super(http);
+       }
+
+       /**
+        * Gets a specific Topology from Traffic Ops
+        *
+        * @param name The name of the Topology to be returned.
+        * @returns The Topology with the given name.
+        */
+       public async getTopologies(name: string): Promise<ResponseTopology>;
+       /**
+        * Gets all Topologies from Traffic Ops
+        *
+        * @returns An Array of all Topologies configured in Traffic Ops.
+        */
+       public async getTopologies(): Promise<Array<ResponseTopology>>;
+       /**
+        * Gets one or all Topologies from Traffic Ops
+        *
+        * @param name The name of a single Topology to be returned.
+        * @returns Either an Array of Topology objects, or a single Topology, 
depending on
+        * whether `name` was   passed.
+        */
+       public async getTopologies(name?: string): 
Promise<Array<ResponseTopology> | ResponseTopology> {
+               const path = "topologies";
+               if (name) {
+                       const topology = await 
this.get<[ResponseTopology]>(path, undefined, {name}).toPromise();
+                       if (topology.length !== 1) {
+                               throw new Error(`${topology.length} Topologies 
found by name ${name}`);
+                       }
+                       return topology[0];
+               }
+               return this.get<Array<ResponseTopology>>(path).toPromise();
+       }
+
+       /**
+        * Deletes a Topology.
+        *
+        * @param topology The Topology to be deleted, or just its name.
+        */
+       public async deleteTopology(topology: ResponseTopology | string): 
Promise<void> {
+               const name = typeof topology === "string" ? topology : 
topology.name;
+               return this.delete(`topologies?name=${name}`).toPromise();

Review Comment:
   Moved `name` to the `params` argument



##########
experimental/traffic-portal/src/app/api/topology.service.ts:
##########
@@ -0,0 +1,196 @@
+/*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+import { HttpClient } from "@angular/common/http";
+import { Injectable } from "@angular/core";
+import type {
+       RequestTopology,
+       ResponseTopology,
+       ResponseTopologyNode,
+} from "trafficops-types";
+
+import { APIService } from "./base-api.service";
+
+/**
+ * TopTreeNode is used to represent a topology in a format usable as a material
+ * nested tree data source.
+ */
+export interface TopTreeNode {
+       name: string;
+       cachegroup: string;
+       children: Array<TopTreeNode>;
+       parents: Array<this>;
+}
+
+/**
+ * TopologyService exposes API functionality relating to Topologies.
+ */
+@Injectable()
+export class TopologyService extends APIService {
+
+       constructor(http: HttpClient) {
+               super(http);
+       }
+
+       /**
+        * Gets a specific Topology from Traffic Ops
+        *
+        * @param name The name of the Topology to be returned.
+        * @returns The Topology with the given name.
+        */
+       public async getTopologies(name: string): Promise<ResponseTopology>;
+       /**
+        * Gets all Topologies from Traffic Ops
+        *
+        * @returns An Array of all Topologies configured in Traffic Ops.
+        */
+       public async getTopologies(): Promise<Array<ResponseTopology>>;
+       /**
+        * Gets one or all Topologies from Traffic Ops
+        *
+        * @param name The name of a single Topology to be returned.
+        * @returns Either an Array of Topology objects, or a single Topology, 
depending on
+        * whether `name` was   passed.
+        */
+       public async getTopologies(name?: string): 
Promise<Array<ResponseTopology> | ResponseTopology> {
+               const path = "topologies";
+               if (name) {
+                       const topology = await 
this.get<[ResponseTopology]>(path, undefined, {name}).toPromise();
+                       if (topology.length !== 1) {
+                               throw new Error(`${topology.length} Topologies 
found by name ${name}`);
+                       }
+                       return topology[0];
+               }
+               return this.get<Array<ResponseTopology>>(path).toPromise();
+       }
+
+       /**
+        * Deletes a Topology.
+        *
+        * @param topology The Topology to be deleted, or just its name.
+        */
+       public async deleteTopology(topology: ResponseTopology | string): 
Promise<void> {
+               const name = typeof topology === "string" ? topology : 
topology.name;
+               return this.delete(`topologies?name=${name}`).toPromise();
+       }
+
+       /**
+        * Creates a new Topology.
+        *
+        * @param topology The Topology to create.
+        */
+       public async createTopology(topology: RequestTopology): 
Promise<ResponseTopology> {
+               return this.post<ResponseTopology>("topologies", 
topology).toPromise();
+       }
+
+       /**
+        * Replaces an existing Topology with the provided new definition of a
+        * Topology.
+        *
+        * @param topology The full new definition of the Topology being updated
+        */
+       public async updateTopology(topology: ResponseTopology): 
Promise<ResponseTopology> {
+               return 
this.put<ResponseTopology>(`topologies?name=${topology.name}`, 
topology).toPromise();

Review Comment:
   Moved `name` to the `params` argument



##########
experimental/traffic-portal/src/app/api/topology.service.ts:
##########
@@ -0,0 +1,196 @@
+/*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+import { HttpClient } from "@angular/common/http";
+import { Injectable } from "@angular/core";
+import type {
+       RequestTopology,
+       ResponseTopology,
+       ResponseTopologyNode,
+} from "trafficops-types";
+
+import { APIService } from "./base-api.service";
+
+/**
+ * TopTreeNode is used to represent a topology in a format usable as a material
+ * nested tree data source.
+ */
+export interface TopTreeNode {
+       name: string;
+       cachegroup: string;
+       children: Array<TopTreeNode>;
+       parents: Array<this>;
+}
+
+/**
+ * TopologyService exposes API functionality relating to Topologies.
+ */
+@Injectable()
+export class TopologyService extends APIService {
+
+       constructor(http: HttpClient) {
+               super(http);
+       }
+
+       /**
+        * Gets a specific Topology from Traffic Ops
+        *
+        * @param name The name of the Topology to be returned.
+        * @returns The Topology with the given name.
+        */
+       public async getTopologies(name: string): Promise<ResponseTopology>;
+       /**
+        * Gets all Topologies from Traffic Ops
+        *
+        * @returns An Array of all Topologies configured in Traffic Ops.
+        */
+       public async getTopologies(): Promise<Array<ResponseTopology>>;
+       /**
+        * Gets one or all Topologies from Traffic Ops
+        *
+        * @param name The name of a single Topology to be returned.
+        * @returns Either an Array of Topology objects, or a single Topology, 
depending on
+        * whether `name` was   passed.
+        */
+       public async getTopologies(name?: string): 
Promise<Array<ResponseTopology> | ResponseTopology> {
+               const path = "topologies";
+               if (name) {
+                       const topology = await 
this.get<[ResponseTopology]>(path, undefined, {name}).toPromise();
+                       if (topology.length !== 1) {
+                               throw new Error(`${topology.length} Topologies 
found by name ${name}`);
+                       }
+                       return topology[0];
+               }
+               return this.get<Array<ResponseTopology>>(path).toPromise();
+       }
+
+       /**
+        * Deletes a Topology.
+        *
+        * @param topology The Topology to be deleted, or just its name.
+        */
+       public async deleteTopology(topology: ResponseTopology | string): 
Promise<void> {
+               const name = typeof topology === "string" ? topology : 
topology.name;
+               return this.delete(`topologies?name=${name}`).toPromise();
+       }
+
+       /**
+        * Creates a new Topology.
+        *
+        * @param topology The Topology to create.
+        */
+       public async createTopology(topology: RequestTopology): 
Promise<ResponseTopology> {
+               return this.post<ResponseTopology>("topologies", 
topology).toPromise();
+       }
+
+       /**
+        * Replaces an existing Topology with the provided new definition of a
+        * Topology.
+        *
+        * @param topology The full new definition of the Topology being updated
+        */
+       public async updateTopology(topology: ResponseTopology): 
Promise<ResponseTopology> {

Review Comment:
   Added a `name` argument



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to