46 lines
1.4 KiB
TypeScript
46 lines
1.4 KiB
TypeScript
import {Injectable} from '@angular/core';
|
|
import {HttpClient, HttpParams} from '@angular/common/http';
|
|
import {Preset} from '../interfaces/preset.interface';
|
|
import {Result} from '../interfaces/result.interface';
|
|
import {Region} from '../interfaces/region.interface';
|
|
import {MOCK_PRESETS, MOCK_REGIONS, MOCK_RESULT} from '../mock/mock-data';
|
|
|
|
@Injectable({
|
|
providedIn: 'root'
|
|
})
|
|
export class DataService {
|
|
|
|
private readonly API_URL = 'https://example.com/api/v1';
|
|
|
|
constructor(private http: HttpClient) {
|
|
}
|
|
|
|
public searchRegions(query: string): Promise<Result[]> {
|
|
const params = new HttpParams();
|
|
params.append('q', query);
|
|
|
|
// return this.http.get<Result[]>(this.API_URL + '/search', {params}).toPromise();
|
|
return new Promise<Result[]>(resolve => {
|
|
resolve(MOCK_RESULT);
|
|
});
|
|
}
|
|
|
|
public getAllPresets(): Promise<Preset[]> {
|
|
// return this.http.get<Preset[]>(this.API_URL + '/search/presets').toPromise();
|
|
return new Promise<Preset[]>(resolve => {
|
|
resolve(MOCK_PRESETS);
|
|
});
|
|
}
|
|
|
|
public getAllRegions(): Promise<Region[]> {
|
|
// return this.http.get<Region[]>(this.API_URL + '/regions').toPromise();
|
|
return new Promise<Region[]>(resolve => {
|
|
resolve(MOCK_REGIONS);
|
|
});
|
|
}
|
|
|
|
public getRegion(id: number): Promise<Region> {
|
|
return this.http.get<Region>(`${this.API_URL}/regions/${id}`).toPromise();
|
|
}
|
|
}
|