Add basic interface and data service

This commit is contained in:
Patrick Gebhardt 2020-06-09 23:18:51 +02:00 committed by Patrick Gebhardt
parent 316cb4f663
commit 53cd7c6245
5 changed files with 50 additions and 0 deletions

View File

@ -0,0 +1,7 @@
/** Represents the structure of a search preset. */
export interface Preset {
preset_id: number;
parameter: string;
tag_label: string;
value: number[];
}

View File

@ -0,0 +1,6 @@
/** Represents the structure of a region. */
export interface Region {
region_id: number;
name: string;
country: string;
}

View File

@ -0,0 +1,7 @@
/** Represents the structure of one search result. */
export interface Result {
region_id: string;
region_name: string;
score: number;
scores: any[];
}

View File

@ -0,0 +1,12 @@
import { TestBed } from '@angular/core/testing';
import { DataService } from './data.service';
describe('DataService', () => {
beforeEach(() => TestBed.configureTestingModule({}));
it('should be created', () => {
const service: DataService = TestBed.get(DataService);
expect(service).toBeTruthy();
});
});

View File

@ -0,0 +1,18 @@
import {Injectable} from '@angular/core';
import {HttpClient} from '@angular/common/http';
import {Preset} from '../interfaces/preset.interface';
@Injectable({
providedIn: 'root'
})
export class DataService {
private readonly API_URL = 'https://example.com/api/v1/';
constructor(private http: HttpClient) {
}
public getPresets(): Promise<Preset[]> {
return this.http.get<Preset[]>(this.API_URL + 'presets').toPromise();
}
}