Merge branch 'feature/interfaces' into 'develop'
Feature/interfaces See merge request tjohn/cc-data!2
This commit is contained in:
commit
65219907f8
7
frontend/src/app/interfaces/preset.interface.ts
Normal file
7
frontend/src/app/interfaces/preset.interface.ts
Normal 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[];
|
||||
}
|
||||
6
frontend/src/app/interfaces/region.interface.ts
Normal file
6
frontend/src/app/interfaces/region.interface.ts
Normal file
@ -0,0 +1,6 @@
|
||||
/** Represents the structure of a region. */
|
||||
export interface Region {
|
||||
region_id: number;
|
||||
name: string;
|
||||
country: string;
|
||||
}
|
||||
15
frontend/src/app/interfaces/result.interface.ts
Normal file
15
frontend/src/app/interfaces/result.interface.ts
Normal file
@ -0,0 +1,15 @@
|
||||
import {SearchParam} from './search-request.interface';
|
||||
|
||||
/** Represents the structure of one search result. */
|
||||
export interface Result {
|
||||
region_id: string;
|
||||
region_name: string;
|
||||
score: number;
|
||||
scores: Score[];
|
||||
}
|
||||
|
||||
export interface Score {
|
||||
type: SearchParam;
|
||||
value: number;
|
||||
score: number;
|
||||
}
|
||||
25
frontend/src/app/interfaces/search-request.interface.ts
Normal file
25
frontend/src/app/interfaces/search-request.interface.ts
Normal file
@ -0,0 +1,25 @@
|
||||
export enum SearchParam {
|
||||
FROM = 'from',
|
||||
TO = 'to',
|
||||
TEMPERATURE = 'temperature',
|
||||
PRECIPITATION = 'precipitation',
|
||||
RAINDAYS = 'raindays',
|
||||
HUMIDITY = 'humidity',
|
||||
SUNHOURS = 'sunhours',
|
||||
ALCOHOL = 'alcohol',
|
||||
FOOD = 'food'
|
||||
}
|
||||
|
||||
export interface SearchParams {
|
||||
from: number;
|
||||
to: number;
|
||||
price?: number[];
|
||||
exclude_region_ids?: number[];
|
||||
temperature?: number[];
|
||||
precipitation?: number[];
|
||||
raindays?: number[];
|
||||
humidity?: number[];
|
||||
sunhours?: number[];
|
||||
alcohol?: number[];
|
||||
food?: number[];
|
||||
}
|
||||
12
frontend/src/app/services/data.service.spec.ts
Normal file
12
frontend/src/app/services/data.service.spec.ts
Normal 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();
|
||||
});
|
||||
});
|
||||
36
frontend/src/app/services/data.service.ts
Normal file
36
frontend/src/app/services/data.service.ts
Normal file
@ -0,0 +1,36 @@
|
||||
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 {SearchParams} from '../interfaces/search-request.interface';
|
||||
import {Region} from '../interfaces/region.interface';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class DataService {
|
||||
|
||||
private readonly API_URL = 'https://example.com/api/v1/';
|
||||
|
||||
constructor(private http: HttpClient) {
|
||||
}
|
||||
|
||||
public searchRegions(searchParams: SearchParams): Promise<Result[]> {
|
||||
const params = new HttpParams();
|
||||
params.append('q', btoa(JSON.stringify(searchParams)));
|
||||
|
||||
return this.http.get<Result[]>(this.API_URL + 'search', {params}).toPromise();
|
||||
}
|
||||
|
||||
public getAllPresets(): Promise<Preset[]> {
|
||||
return this.http.get<Preset[]>(this.API_URL + 'preset').toPromise();
|
||||
}
|
||||
|
||||
public getAllRegions(): Promise<Region[]> {
|
||||
return this.http.get<Region[]>(this.API_URL + 'region').toPromise();
|
||||
}
|
||||
|
||||
public toMinMaxArray(min: number, max: number): number[] {
|
||||
return [min, max];
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user