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

src.app.core.services.backups.service.ts Maven / Gradle / Ivy

There is a newer version: 3.0.0
Show newest version
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';

import { environment } from '@env/environment';
import { Backup } from '@core/model/backups.model';

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

    private url = '/api/v1/backups';

    constructor(private http: HttpClient) {
    }

    public list(): Observable> {
        return this.http.get>(environment.backend + this.url).pipe(
            map(dtos => this.mapToBackups(dtos))
        );
    }

    public get(backup: Backup): Observable {
        return this.http.get(
            environment.backend + this.url + `/${backup.id()}`).pipe(
            map(dto => this.mapToBackup(dto))
        );
    }

    public delete(backup: Backup): Observable {
        return this.http.delete(environment.backend + this.url + `/${backup.id()}`)
            .pipe(map(() => {}));
    }

    public download(backup: Backup): Observable {
        const options: any = {
            responseType: 'arraybuffer'
        };
        return this.http.get(environment.backend + this.url + `/${backup.id()}` + '/download', options);
    }

    public save(backup: BackupDto): Observable {
        return this.http.post(environment.backend + this.url, backup, {responseType: 'text'});
    }

    private mapToBackup(dto: BackupDto): Backup {
        return new Backup(dto.homePage, dto.agentsNetwork, dto.environments, dto.components, dto.globalVars, dto.jiraLinks, dto.time);
    }

    private mapToBackups(dtos: BackupDto[]): Backup[] {
        return dtos.map(dto => this.mapToBackup(dto));
    }
}

export class BackupDto {
    constructor(
        public homePage: boolean,
        public agentsNetwork: boolean,
        public environments: boolean,
        public components: boolean,
        public globalVars: boolean,
        public jiraLinks: boolean,
        public time?: Date) {
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy