Update interfaces
This commit is contained in:
parent
9c3f70d36b
commit
de443bb5de
@ -10,13 +10,15 @@ import {Router} from '@angular/router';
|
|||||||
})
|
})
|
||||||
export class HomeComponent implements OnInit {
|
export class HomeComponent implements OnInit {
|
||||||
|
|
||||||
|
private readonly MAX_REGIONS = 10;
|
||||||
|
|
||||||
regions: Region[];
|
regions: Region[];
|
||||||
|
|
||||||
constructor(private ds: DataService, private router: Router) {
|
constructor(private ds: DataService, private router: Router) {
|
||||||
}
|
}
|
||||||
|
|
||||||
async ngOnInit() {
|
async ngOnInit() {
|
||||||
this.regions = await this.ds.getAllRegions();
|
this.regions = await this.ds.getAllRegions(this.MAX_REGIONS);
|
||||||
}
|
}
|
||||||
|
|
||||||
onRegionClick(region: Region) {
|
onRegionClick(region: Region) {
|
||||||
|
|||||||
@ -12,6 +12,9 @@ export interface Query {
|
|||||||
entertainment_costs?: number[];
|
entertainment_costs?: number[];
|
||||||
accommodation_costs?: number[];
|
accommodation_costs?: number[];
|
||||||
average_per_day_costs?: number[];
|
average_per_day_costs?: number[];
|
||||||
|
fulltext?: boolean;
|
||||||
|
textfilter?: string;
|
||||||
|
showRegionsWithNullScore?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum SearchParameter {
|
export enum SearchParameter {
|
||||||
|
|||||||
@ -36,8 +36,12 @@ export class DataService {
|
|||||||
// });
|
// });
|
||||||
}
|
}
|
||||||
|
|
||||||
public async getAllRegions(): Promise<Region[]> {
|
public async getAllRegions(max?: number): Promise<Region[]> {
|
||||||
const regions = await this.http.get<Region[]>(this.API_URL + '/regions').toPromise();
|
let params = new HttpParams();
|
||||||
|
if (max) {
|
||||||
|
params = params.set('randomize', max.toString(10));
|
||||||
|
}
|
||||||
|
const regions = await this.http.get<Region[]>(this.API_URL + '/regions', {params}).toPromise();
|
||||||
|
|
||||||
regions.forEach(region => this.regionCache.set(region.region_id, region));
|
regions.forEach(region => this.regionCache.set(region.region_id, region));
|
||||||
|
|
||||||
@ -51,7 +55,6 @@ export class DataService {
|
|||||||
|
|
||||||
public async getRegion(id: number): Promise<Region> {
|
public async getRegion(id: number): Promise<Region> {
|
||||||
if (this.regionCache.has(id)) {
|
if (this.regionCache.has(id)) {
|
||||||
console.log(`Served region ${id} from cache`);
|
|
||||||
return this.regionCache.get(id);
|
return this.regionCache.get(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user