31 lines
938 B
TypeScript
31 lines
938 B
TypeScript
|
import {Injectable} from '@angular/core';
|
||
|
import {HttpClient} from '@angular/common/http';
|
||
|
import {AppConfig} from '../shared/app.config';
|
||
|
import {Observable} from 'rxjs';
|
||
|
|
||
|
@Injectable()
|
||
|
export class SchemaService {
|
||
|
constructor(private httpClient: HttpClient, private appConfig: AppConfig) {
|
||
|
}
|
||
|
|
||
|
ApiEndpoint() {
|
||
|
return this.appConfig.getConfig('apiEndPoint');
|
||
|
}
|
||
|
|
||
|
public getSchemaIdFromSchemaUrl(schemaUrl): string {
|
||
|
const url = new URL(schemaUrl);
|
||
|
const pathSplit = url.pathname.split('/');
|
||
|
|
||
|
return pathSplit[pathSplit.length - 1].replace('.json', '');
|
||
|
}
|
||
|
|
||
|
public getSchemaWithUrl(schemaUrl): Observable<string> {
|
||
|
const id = this.getSchemaIdFromSchemaUrl(schemaUrl);
|
||
|
return this.httpClient.get<any>(`${this.ApiEndpoint()}/api/v1/schema/${id}`);
|
||
|
}
|
||
|
|
||
|
public getSchemaWithId(schemaId): Observable<string> {
|
||
|
return this.httpClient.get<any>(`${this.ApiEndpoint()}/api/v1/schema/${schemaId}`);
|
||
|
}
|
||
|
}
|