From db5c7fbbe7518d2fae2ca0a95a390f508a19d1e3 Mon Sep 17 00:00:00 2001 From: Patrick Gebhardt Date: Sun, 14 Jun 2020 15:12:18 +0200 Subject: [PATCH] Add base64 encoding for search request --- .../src/app/interfaces/result.interface.ts | 10 +++++++- .../interfaces/search-request.interface.ts | 25 +++++++++++++++++++ frontend/src/app/services/data.service.ts | 24 +++++++++++++++--- 3 files changed, 55 insertions(+), 4 deletions(-) create mode 100644 frontend/src/app/interfaces/search-request.interface.ts diff --git a/frontend/src/app/interfaces/result.interface.ts b/frontend/src/app/interfaces/result.interface.ts index a06649d..1ca48be 100644 --- a/frontend/src/app/interfaces/result.interface.ts +++ b/frontend/src/app/interfaces/result.interface.ts @@ -1,7 +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: any[]; + scores: Score[]; +} + +export interface Score { + type: SearchParam; + value: number; + score: number; } diff --git a/frontend/src/app/interfaces/search-request.interface.ts b/frontend/src/app/interfaces/search-request.interface.ts new file mode 100644 index 0000000..1095fb6 --- /dev/null +++ b/frontend/src/app/interfaces/search-request.interface.ts @@ -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[]; +} diff --git a/frontend/src/app/services/data.service.ts b/frontend/src/app/services/data.service.ts index ffe7f71..d9714a1 100644 --- a/frontend/src/app/services/data.service.ts +++ b/frontend/src/app/services/data.service.ts @@ -1,6 +1,9 @@ import {Injectable} from '@angular/core'; -import {HttpClient} from '@angular/common/http'; +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' @@ -12,7 +15,22 @@ export class DataService { constructor(private http: HttpClient) { } - public getPresets(): Promise { - return this.http.get(this.API_URL + 'presets').toPromise(); + public searchRegions(searchParams: SearchParams): Promise { + const params = new HttpParams(); + params.append('q', btoa(JSON.stringify(searchParams))); + + return this.http.get(this.API_URL + 'search', {params}).toPromise(); + } + + public getAllPresets(): Promise { + return this.http.get(this.API_URL + 'preset').toPromise(); + } + + public getAllRegions(): Promise { + return this.http.get(this.API_URL + 'region').toPromise(); + } + + public toMinMaxArray(min: number, max: number): number[] { + return [min, max]; } }