Skip to content

Commit

Permalink
water-fountains#146 remove deprecated id_operator
Browse files Browse the repository at this point in the history
  • Loading branch information
robstoll committed Dec 17, 2021
1 parent c6dfade commit 43e18de
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 21 deletions.
9 changes: 7 additions & 2 deletions server/api/controllers/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import {
import sharedConstants from './../../common/shared-constants';
import { Request, Response } from 'express';
import { getSingleBooleanQueryParam, getSingleNumberQueryParam, getSingleStringQueryParam } from './utils';
import { Fountain, FountainCollection, GalleryValue } from '../../common/typealias';
import { Fountain, FountainCollection, GalleryValue, isDatabase } from '../../common/typealias';
import { hasWikiCommonsCategories } from '../../common/wikimedia-types';
import { ImageLike } from '../../../config/text2img';

Expand Down Expand Up @@ -251,6 +251,11 @@ function sendJson(resp: Response, obj: Record<string, any> | undefined, dbg: str
*/
function byId(req: Request, res: Response, dbg: string): Promise<Fountain | undefined> {
const city = getSingleStringQueryParam(req, 'city');
const database = getSingleStringQueryParam(req, 'database');
if (!isDatabase(database)) {
return new Promise((_, reject) => reject('unsupported database given: ' + database));
}

let name = 'unkNamById';
// l.info('controller.js byId: '+cityS+' '+dbg);
let fountainCollection = cityCache.get<FountainCollection>(city);
Expand All @@ -270,7 +275,7 @@ function byId(req: Request, res: Response, dbg: string): Promise<Fountain | unde
}
if (fountainCollection !== undefined) {
const fountain = fountainCollection.features.find(
f => f.properties['id_' + req.query.database]?.value === req.query.idval
f => f.properties['id_' + database]?.value === req.query.idval
);
const imgMetaPromises: Promise<any>[] = [];
let lazyAdded = 0;
Expand Down
10 changes: 3 additions & 7 deletions server/api/services/database.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,7 @@ function replaceFountain(

function isMatch(f1: Fountain, f2: Fountain): boolean {
// returns true if match, otherwise returns distance
const ids = ['id_wikidata', 'id_operator', 'id_osm'];
for (const id_name of ids) {
if (f1.properties && f2.properties && f1.properties[id_name].value === f2.properties[id_name].value) {
return true;
}
}
return false;
return ['id_wikidata', 'id_osm'].some(idName => {
f1.properties && f2.properties && f1.properties[idName].value === f2.properties[idName].value;
});
}
6 changes: 3 additions & 3 deletions server/common/build.info.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// this file is automatically generated by git.version.js script
const buildInfo = {
version: '',
revision: '82e1956',
revision: 'c6dfade',
branch: 'develop',
commit_time: '2021-10-18 20:23:30 +0200',
build_time: 'Wed Oct 27 2021 10:04:56 GMT+0200 (Central European Summer Time)',
commit_time: '2021-10-27 08:30:58 +0000',
build_time: 'Fri Dec 17 2021 23:35:27 GMT+0100 (Central European Standard Time)',
};
export default buildInfo;
15 changes: 7 additions & 8 deletions server/common/swagger/Api.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
swagger: "2.0"
swagger: '2.0'
info:
version: 1.0.0
title: datablue
Expand All @@ -18,7 +18,6 @@ produces:
- application/json
- text/html


definitions:
ExampleBody:
type: object
Expand All @@ -33,25 +32,25 @@ definitions:
paths:
/metadata/fountain_properties:
get:
description: "Fetch general metadata for fountain properties. For example: whether OpenStreetMap or Wikidata are preferred places to store the information."
description: 'Fetch general metadata for fountain properties. For example: whether OpenStreetMap or Wikidata are preferred places to store the information.'
responses:
200:
description: Returns property metadata.

/metadata/locations:
get:
description: "Fetch general metadata for locations, including bounds and official operator information."
description: 'Fetch general metadata for locations, including bounds and official operator information.'
responses:
200:
description: Returns location metadata.

/metadata/shared-constants:
get:
description: "Fetch shared consants between Datablue and Proximap."
description: 'Fetch shared consants between Datablue and Proximap.'
responses:
200:
description: Returns shared constants.

/fountain:
get:
description: Fetch detailed fountain information based on coordinates or identifier
Expand All @@ -66,7 +65,7 @@ paths:
- name: database
in: query
type: string
enum: [datablue, operator, wikidata, osm]
enum: [wikidata, osm]
example: wikidata
description: database for which the provided identifier is valid
- name: city
Expand Down Expand Up @@ -153,7 +152,7 @@ paths:
responses:
200:
description: Returns the build information.

/spec:
get:
tags:
Expand Down
10 changes: 9 additions & 1 deletion server/common/typealias.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,12 @@ export interface SourceConfig<V, RE> {
// if you change something here, then you need to change it in proximap as well
//TODO @ralfhauser looks suspicious/buggy to me, IMO we always know that it is either osm or wikidata, shall I change/fix this?
// this currently occurs if metadata.src_config['osm'] or metadata.src_config['wikidata'] returns null in conflate.data.service.ts
export type SourceType = 'osm' | 'wikidata' | '';
export type SourceType = keyof NamedSources<unknown, unknown> | '';

// 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 datablue as well
export type Database = SourceType;

export function isDatabase(d: string): d is Database {
return d === 'osm' || d === 'wikidata';
}

0 comments on commit 43e18de

Please sign in to comment.