Découpage en 1 service par composant

This commit is contained in:
Sébastien André
2020-01-28 17:25:26 +01:00
parent 9f3042ed37
commit 9dbabba5a2
17 changed files with 237 additions and 186 deletions

View File

@@ -0,0 +1,52 @@
import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';
import { environment } from '../environments/environment';
import { DropZoneResp } from '../models/dropzone';
@Injectable()
export class DropzoneService {
private readonly headers = new HttpHeaders({
'Access-Control-Allow-Origin': environment.urlApi
});
constructor(private http: HttpClient) { }
public getListOfDropZones(): Observable<Array<DropZoneResp>> {
return this.http
.get<Array<DropZoneResp>>(`${environment.urlApi}/api/DropZone`, {
headers: this.headers
})
.pipe(
map(response => {
const details = response.map(data => new DropZoneResp(data));
return details;
})
);
}
public SetFavoriteDropZone(selectedDz: DropZoneResp): boolean {
selectedDz.isFavorite = true;
this.http
.put(`${environment.urlApi}/api/DropZone/${selectedDz.id}`, selectedDz, {
headers: this.headers
})
.subscribe(data => console.log(data));
return true;
}
public RemoveFavoriteDropZone(selectedDz: DropZoneResp): boolean {
selectedDz.isFavorite = false;
this.http
.put(`${environment.urlApi}/api/DropZone/${selectedDz.id}`, selectedDz, {
headers: this.headers
})
.subscribe(data => console.log(data));
return true;
}
}