80 lines
1.9 KiB
TypeScript
80 lines
1.9 KiB
TypeScript
import { Injectable } from "@angular/core";
|
|
import { HttpClient } from "@angular/common/http";
|
|
import { Observable } from "rxjs";
|
|
import { map } from "rxjs/operators";
|
|
|
|
import { DropZoneResp, DropZoneReq } from "../models/dropzone";
|
|
|
|
import { BaseService } from "./base.service";
|
|
|
|
@Injectable()
|
|
export class DropzoneService extends BaseService {
|
|
constructor(private http: HttpClient) {
|
|
super();
|
|
}
|
|
|
|
public getListOfDropZones(): Observable<Array<DropZoneResp>> {
|
|
return this.http
|
|
.get<Array<DropZoneResp>>(`${this.apiUrl}/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(`${this.apiUrl}/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(`${this.apiUrl}/DropZone/${selectedDz.id}`, selectedDz, {
|
|
headers: this.headers
|
|
})
|
|
.subscribe(data => console.log(data));
|
|
|
|
return true;
|
|
}
|
|
|
|
public AddDropZone(
|
|
latitude: string,
|
|
longitude: string,
|
|
name: string,
|
|
address: string,
|
|
website: string,
|
|
email: string,
|
|
type: Array<string>,
|
|
isFavorite: boolean
|
|
) {
|
|
const bodyNewDropZone: DropZoneReq = {
|
|
id: 0,
|
|
latitude: latitude,
|
|
longitude: longitude,
|
|
name: name,
|
|
address: address,
|
|
website: website,
|
|
email: email,
|
|
type: type,
|
|
isFavorite: isFavorite
|
|
};
|
|
|
|
this.http
|
|
.post(`${this.apiUrl}/DropZone`, bodyNewDropZone, {
|
|
headers: this.headers
|
|
})
|
|
.subscribe(data => console.log(data));
|
|
}
|
|
}
|