All Downloads are FREE. Search and download functionalities are using the official Maven repository.

src.app.core.services.environment-admin.service.ts Maven / Gradle / Ivy

import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { EnvironmentMetadata, Target } from '@model';
import { environment as server } from '../../../environments/environment';
import { HttpClient } from '@angular/common/http';
import { map } from 'rxjs/operators';

@Injectable({
    providedIn: 'root'
})
export class EnvironmentAdminService {

    private baseUrl = '/api/v2/environment';

    constructor(private http: HttpClient) {}

    listEnvironments(): Observable> {
        return this.http.get>(server.backend + this.baseUrl).pipe(map((res: Array) => {
            return res.sort((t1, t2) => t1.name.toUpperCase() > t2.name.toUpperCase() ? 1 : 0);
        }));
    }

    listEnvironmentsNames(): Observable> {
        return this.http.get>(server.backend + this.baseUrl + '/names');
    }

    exportEnvironment(environmentName: string): Observable> {
        return this.http.get>(server.backend + this.baseUrl + '/' + environmentName);
    }

    createEnvironment(environment: EnvironmentMetadata): Observable {
        return this.http.post(server.backend + this.baseUrl, environment);
    }

    updateEnvironment(environmentName: string, environment: EnvironmentMetadata): Observable {
        return this.http.put(server.backend + this.baseUrl + '/' + environmentName, environment);
    }

    listTargets(environmentName: string): Observable> {
        return this.http.get>(server.backend + this.baseUrl + '/' + environmentName + '/target');
    }

    targets(): Observable> {
        return this.http.get>(server.backend + this.baseUrl + '/target');
    }

    targetsNames(): Observable> {
        return this.http.get>(server.backend + this.baseUrl + '/target/names');
    }

    updateTarget(environmentName: string, targetName: string, target: Target): Observable {
        return this.http.put(server.backend + this.baseUrl + '/' + environmentName + '/target/' + targetName, target);
    }

    addTarget(environmentName: string, target: Target): Observable {
        return this.http.post(server.backend + this.baseUrl + '/' + environmentName + '/target', target);
    }

    deleteTarget(environmentName: string, targetName: string): Observable {
        return this.http.delete(server.backend + this.baseUrl + '/' + environmentName + '/target/' + targetName);
    }

    exportTarget(environmentName: string, targetName: string): Observable {
        return this.http.get(server.backend + this.baseUrl + '/' + environmentName + '/target/' + targetName);
    }

}