Skip to content

Commit

Permalink
water-fountains#148 fetch by bounds instead of city
Browse files Browse the repository at this point in the history
the /fountains endpoint now requires sw and ne query parameter instead of city

moreover:
- require a location for byId so that we can look it up in cache
- fix TestCityBounds (water-fountains#157)
- failure handling for cache populati
- send 404 in case json object is undefined (and not only log error
  and send undefined)
- catch errors and send to next middleware (water-fountains#155)
- removed database.service.ts
- increased REQUEST_LIMIT to 10MB as we query more fountains now
- updated Api.yaml accordingly
- updated express from 4.17.1 to 4.17.2
- update node-cache from 4.2.1 to 5.1.2

cleanup:
- use BoundingBox instead of separate minLng, minLat... as parameter
- added last_scan to FountainCollection and provide a factory function
  which set it automatically to new Date()
- fix binding in router.ts
  • Loading branch information
robstoll committed Dec 22, 2021
1 parent 11e097b commit aa6848b
Show file tree
Hide file tree
Showing 23 changed files with 1,267 additions and 910 deletions.
2 changes: 1 addition & 1 deletion .envTEMPLATE
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
APP_ID=datablue
PORT=3000
LOG_LEVEL=debug
REQUEST_LIMIT=100kb
REQUEST_LIMIT=10MB
GOOGLE_API_KEY=mykey
SESSION_SECRET=mySecret
NODE_ENV=development
Expand Down
24 changes: 21 additions & 3 deletions config/locations.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Translated } from '../server/common/typealias';
import { BoundingBox, Translated, uncheckedBoundingBoxToChecked } from '../server/common/typealias';

/*
* @license
Expand All @@ -19,14 +19,16 @@ export interface Location {
name: string;
description: Translated<string>;
description_more: Translated<string>;
bounding_box: BoundingBox;
bounding_box: UncheckedBoundingBox;
//TODO @ralf.hauser not used as it seems, remove?
operator_fountain_catalog_qid: string;
//TODO @ralf.hauser not used as it seems, remove?
issue_api: IssueApi;
}

// TODO it would make more sense to move common types to an own library which is consumed by both, datablue and proximap
// if you change something here, then you need to change it in proximap as well
export interface BoundingBox {
export interface UncheckedBoundingBox {
latMin: number;
lngMin: number;
latMax: number;
Expand Down Expand Up @@ -521,7 +523,23 @@ export function isCity(s: string): s is City {
return cities.includes(s as City);
}

// TODO it would make more sense to move common types to an own library which is consumed by both, datablue and proximap
// if you change something here, then you need to change it in proximap as well
export function getCityBoundingBox(city: City): BoundingBox {
const uncheckedBoundingBox = locationsCollection[city].bounding_box;
try {
return uncheckedBoundingBoxToChecked(uncheckedBoundingBox);
} catch (e: any) {
const newErr = new Error('Could not get city bounding box for ' + city);
newErr.stack += '\nCaused by: ' + e.stack;
throw newErr;
}
}

// TODO it would make more sense to move common types to an own library which is consumed by both, datablue and proximap
// if you change something here, then you need to change it in proximap as well
export type LocationsCollection = Record<City, Location>;

// we don't expose just the internal structure as we also want to be sure that it follows the spec.
// However, we allow City union to grow dynamically
export const locationsCollection: LocationsCollection = internalLocationsCollection;
Expand Down
Loading

0 comments on commit aa6848b

Please sign in to comment.