src.app.core.services.dataset.service.ts Maven / Gradle / Ivy
The newest version!
/*
* SPDX-FileCopyrightText: 2017-2024 Enedis
*
* SPDX-License-Identifier: Apache-2.0
*
*/
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';
import { environment } from '@env/environment';
import { Dataset, KeyValue } from '@model';
import { HttpClient, HttpParams } from '@angular/common/http';
@Injectable({
providedIn: 'root'
})
export class DataSetService {
private resourceUrl = '/api/v1/datasets';
constructor(private httpClient: HttpClient) {
}
findAll(usage: boolean = false): Observable> {
let params = new HttpParams();
params = params.append('usage', usage ? 'true' : 'false');
return this.httpClient.get>(environment.backend + this.resourceUrl, { params })
.pipe(map((res: Array) => {
res = res.map(dto => {
return new Dataset(
dto.name,
dto.description,
dto.tags,
dto.lastUpdated,
dto.uniqueValues,
dto.multipleValues,
dto.id,
dto.scenarioUsage,
dto.campaignUsage,
dto.scenarioInCampaignUsage,
)
});
return res;
}));
}
findById(id: string): Observable {
return this.httpClient.get(environment.backend + this.resourceUrl + '/' + id)
.pipe(
map(dto => this.fromDto(dto))
);
}
save(dataset: Dataset, oldId?: string): Observable {
DataSetService.cleanTags(dataset);
if (dataset.id && dataset.id.length > 0) {
return this.httpClient.put(environment.backend + this.resourceUrl, dataset, {params: {oldId}})
.pipe(
map(dto => this.fromDto(dto))
);
} else {
return this.httpClient.post(environment.backend + this.resourceUrl, dataset)
.pipe(
map(dto => this.fromDto(dto))
);
}
}
delete(id: String): Observable
© 2015 - 2024 Weber Informatics LLC | Privacy Policy