refactor: change backend calls
MODIFY
src/app/services/backend/backend.service.ts
src/app/services/backend/backend.service.ts
@@ -4,23 +4,32 @@ import { Observable } from 'rxjs';
import {ConfigService} from '../config/config.service';
import {
IAction,
- IApi, IApiPlanSummary,
+ IApi,
+ IApiPlanSummary,
+ IApiSummary,
IApiVersion,
IApiVersionEndpointSummary,
- IApiVersionSummary, IClient, IClientSummary, IClientVersionSummary,
+ IApiVersionSummary,
+ IClient,
+ IClientSummary,
+ IClientVersionSummary,
IContract,
IContractSummary,
- INewContract, INewOrganization,
+ INewContract,
+ INewOrganization,
IOrganization,
- IOrganizationSummary, IPolicy, IPolicySummary,
+ IOrganizationSummary,
+ IPolicy,
+ IPolicySummary,
ISearchCriteria,
- ISearchResultsApiSummary, IUserPermissions,
+ ISearchResultsApiSummary,
+ IUserPermissions
} from '../../interfaces/ICommunication';
import {IPolicySummaryExt} from '../../interfaces/IPolicySummaryExt';
import {KeycloakHelperService} from '../keycloak-helper/keycloak-helper.service';
@Injectable({
- providedIn: 'root',
+ providedIn: 'root'
})
export class BackendService {
private readonly endpoint: string;
@@ -35,8 +44,8 @@ export class BackendService {
private httpOptions = {
headers: new HttpHeaders({
- 'Content-Type': 'application/json',
- }),
+ 'Content-Type': 'application/json'
+ })
};
/**
@@ -45,7 +54,7 @@ export class BackendService {
public searchApis(
searchCriteria: ISearchCriteria
): Observable<ISearchResultsApiSummary> {
- const path = 'search/apis';
+ const path = 'devportal/apis/search';
return this.http.post(
this.generateUrl(path),
searchCriteria,
@@ -53,6 +62,14 @@ export class BackendService {
) as Observable<ISearchResultsApiSummary>;
}
+ public getFeaturedApis(): Observable<IApiSummary[]> {
+ const path = 'devportal/apis/featured';
+ return this.http.get(
+ this.generateUrl(path),
+ this.httpOptions
+ ) as Observable<IApiSummary[]>;
+ }
+
/**
* Get Api
*/
@@ -71,7 +88,7 @@ export class BackendService {
orgId: string,
apiId: string
): Observable<IApiVersionSummary[]> {
- const path = `organizations/${orgId}/apis/${apiId}/versions`;
+ const path = `devportal/organizations/${orgId}/apis/${apiId}/versions`;
return this.http.get<IApiVersionSummary[]>(
this.generateUrl(path),
this.httpOptions
@@ -86,28 +103,30 @@ export class BackendService {
apiId: string,
version: string
): Observable<IApiVersion> {
- const path = `organizations/${orgId}/apis/${apiId}/versions/${version}`;
+ const path = `devportal/organizations/${orgId}/apis/${apiId}/versions/${version}`;
return this.http.get<IApiVersion>(this.generateUrl(path), this.httpOptions);
}
public getClientOrgs(): Observable<Array<IOrganizationSummary>> {
const username = this.keycloakHelper.getUsername();
const path = `users/${username}/clientorgs`;
- return this.http.get(this.generateUrl(path)) as Observable<
- Array<IOrganizationSummary>
- >;
+ return this.http.get(
+ this.generateUrl(path),
+ this.httpOptions
+ ) as Observable<Array<IOrganizationSummary>>;
}
- public createClient(
- orgId: string,
- clientName: string
- ): Observable<IClient> {
+ public createClient(orgId: string, clientName: string): Observable<IClient> {
const path = `organizations/${orgId}/clients`;
- return this.http.post(this.generateUrl(path), {
+ return this.http.post(
+ this.generateUrl(path),
+ {
name: clientName,
initialVersion: '1.0',
- description: '',
- }) as Observable<IClient>;
+ description: ''
+ },
+ this.httpOptions
+ ) as Observable<IClient>;
}
public createContract(
@@ -119,7 +138,8 @@ export class BackendService {
const path = `organizations/${organizationId}/clients/${clientId}/versions/${versionName}/contracts`;
return this.http.post(
this.generateUrl(path),
- contract
+ contract,
+ this.httpOptions
) as Observable<IContract>;
}
@@ -129,13 +149,20 @@ export class BackendService {
description: ''
};
const path = 'devportal/organizations';
- return this.http.post<IOrganization>(this.generateUrl(path), org);
+ return this.http.post<IOrganization>(
+ this.generateUrl(path),
+ org,
+ this.httpOptions
+ );
}
public getEditableClients(): Observable<IClientSummary[]> {
const username = this.keycloakHelper.getUsername();
const path = `users/${username}/editable-clients`;
- return this.http.get<IClientSummary[]>(this.generateUrl(path));
+ return this.http.get<IClientSummary[]>(
+ this.generateUrl(path),
+ this.httpOptions
+ );
}
public getClientVersions(
@@ -143,7 +170,10 @@ export class BackendService {
clientId: string
): Observable<IClientVersionSummary[]> {
const path = `organizations/${organizationId}/clients/${clientId}/versions`;
- return this.http.get<IClientVersionSummary[]>(this.generateUrl(path));
+ return this.http.get<IClientVersionSummary[]>(
+ this.generateUrl(path),
+ this.httpOptions
+ );
}
public getContracts(
@@ -152,7 +182,10 @@ export class BackendService {
versionName: string
): Observable<IContractSummary[]> {
const path = `organizations/${organizationId}/clients/${clientId}/versions/${versionName}/contracts`;
- return this.http.get<IContractSummary[]>(this.generateUrl(path));
+ return this.http.get<IContractSummary[]>(
+ this.generateUrl(path),
+ this.httpOptions
+ );
}
public getContract(
@@ -162,7 +195,7 @@ export class BackendService {
contractId: number
): Observable<IContract> {
const path = `organizations/${organizationId}/clients/${clientId}/versions/${versionName}/contracts/${contractId}`;
- return this.http.get<IContract>(this.generateUrl(path)) ;
+ return this.http.get<IContract>(this.generateUrl(path), this.httpOptions);
}
public getManagedApiEndpoint(
@@ -172,74 +205,116 @@ export class BackendService {
): Observable<IApiVersionEndpointSummary> {
const path = `organizations/${organizationId}/apis/${apiId}/versions/${versionName}/endpoint`;
return this.http.get<IApiVersionEndpointSummary>(
- this.generateUrl(path)
+ this.generateUrl(path),
+ this.httpOptions
);
}
- public getApiVersionPlans(organizationId: string,
+ public getApiVersionPlans(
+ organizationId: string,
apiId: string,
- apiVersion: string): Observable<IApiPlanSummary[]> {
- const path = `organizations/${organizationId}/apis/${apiId}/versions/${apiVersion}/plans`
- return this.http.get<IApiPlanSummary[]>(this.generateUrl(path));
+ apiVersion: string
+ ): Observable<IApiPlanSummary[]> {
+ const path = `devportal/organizations/${organizationId}/apis/${apiId}/versions/${apiVersion}/plans`;
+ return this.http.get<IApiPlanSummary[]>(
+ this.generateUrl(path),
+ this.httpOptions
+ );
}
- public getPlanPolicySummaries(organizationId: string,
+ public getPlanPolicySummaries(
+ organizationId: string,
planId: string,
- planVersion: string): Observable<IPolicySummaryExt[]> {
- const path = `organizations/${organizationId}/plans/${planId}/versions/${planVersion}/policies`
- return this.http.get<IPolicySummaryExt[]>(this.generateUrl(path))
+ planVersion: string
+ ): Observable<IPolicySummaryExt[]> {
+ const path = `organizations/${organizationId}/plans/${planId}/versions/${planVersion}/policies`;
+ return this.http.get<IPolicySummaryExt[]>(
+ this.generateUrl(path),
+ this.httpOptions
+ );
}
- public getPlanPolicy(organizationId: string,
+ public getPlanPolicy(
+ organizationId: string,
planId: string,
planVersion: string,
- policyId: string): Observable<IPolicy> {
- const path = `organizations/${organizationId}/plans/${planId}/versions/${planVersion}/policies/${policyId}`
- return this.http.get<IPolicy>(this.generateUrl(path))
+ policyId: string
+ ): Observable<IPolicy> {
+ const path = `organizations/${organizationId}/plans/${planId}/versions/${planVersion}/policies/${policyId}`;
+ return this.http.get<IPolicy>(this.generateUrl(path), this.httpOptions);
}
- public getApiPolicySummaries(organizationId: string,
+ public getApiPolicySummaries(
+ organizationId: string,
apiId: string,
- apiVersion: string): Observable<IPolicySummaryExt[]> {
- const path = `organizations/${organizationId}/apis/${apiId}/versions/${apiVersion}/policies`
- return this.http.get<IPolicySummary[]>(this.generateUrl(path)) as Observable<IPolicySummaryExt[]>
+ apiVersion: string
+ ): Observable<IPolicySummaryExt[]> {
+ const path = `devportal/organizations/${organizationId}/apis/${apiId}/versions/${apiVersion}/policies`;
+ return this.http.get<IPolicySummary[]>(
+ this.generateUrl(path),
+ this.httpOptions
+ ) as Observable<IPolicySummaryExt[]>;
}
- public getApiPolicy(organizationId: string,
+ public getApiPolicy(
+ organizationId: string,
apiId: string,
apiVersion: string,
- policyId: string): Observable<IPolicy> {
- const path = `organizations/${organizationId}/apis/${apiId}/versions/${apiVersion}/policies/${policyId}`
- return this.http.get<IPolicy>(this.generateUrl(path))
+ policyId: string
+ ): Observable<IPolicy> {
+ const path = `organizations/${organizationId}/apis/${apiId}/versions/${apiVersion}/policies/${policyId}`;
+ return this.http.get<IPolicy>(this.generateUrl(path), this.httpOptions);
}
- public headApiDefinition(organizationId: string,
+ public headApiDefinition(
+ organizationId: string,
apiId: string,
- apiVersion:string): Observable<any> {
- const path = `organizations/${organizationId}/apis/${apiId}/versions/${apiVersion}/definition`;
- return this.http.head(this.generateUrl(path));
+ apiVersion: string
+ ): Observable<any> {
+ const path = `devportal/organizations/${organizationId}/apis/${apiId}/versions/${apiVersion}/definition`;
+ return this.http.head(this.generateUrl(path), this.httpOptions);
}
public getPermissions(): Observable<IUserPermissions> {
const userId = this.keycloakHelper.getUsername();
const path = `users/${userId}/permissions`;
- return this.http.get<IUserPermissions>(this.generateUrl(path));
+ return this.http.get<IUserPermissions>(
+ this.generateUrl(path),
+ this.httpOptions
+ );
}
public sendAction(action: IAction): Observable<void> {
const path = `actions`;
- return this.http.post<void>(this.generateUrl(path), action);
+ return this.http.post<void>(
+ this.generateUrl(path),
+ action,
+ this.httpOptions
+ );
}
- public breakAllContracts(organizationId: string, clientId: string, clientVersion: string): Observable<void>{
+ public breakAllContracts(
+ organizationId: string,
+ clientId: string,
+ clientVersion: string
+ ): Observable<void> {
const path = `organizations/${organizationId}/clients/${clientId}/versions/${clientVersion}/contracts`;
- return this.http.delete<void>(this.generateUrl(path));
+ return this.http.delete<void>(this.generateUrl(path), this.httpOptions);
}
public deleteClient(organizationId: string, clientId: string) {
- const path = `organizations/${organizationId}/clients/${clientId}`
- return this.http.delete<void>(this.generateUrl(path));
+ const path = `organizations/${organizationId}/clients/${clientId}`;
+ return this.http.delete<void>(this.generateUrl(path), this.httpOptions);
+ }
+
+ public getPolicyProbe(contract: IContract, policy: IPolicy): Observable<any> {
+ const path = `organizations/${contract.client.client.organization.id}/clients/${contract.client.id}/versions/${contract.client.version}/contracts/${contract.id}/policies/${policy.id}`;
+ return this.http.post(
+ this.generateUrl(path),
+ {apiKey: contract.client.apikey},
+ this.httpOptions
+ ) as Observable<any>;
}
/********* Helper **********/

refactor: change backend calls