diff --git a/Express/barAndCafe/src/openTripMaps.ts b/Express/barAndCafe/src/openTripMaps.ts index 7d4ca1b..2ef91d0 100644 --- a/Express/barAndCafe/src/openTripMaps.ts +++ b/Express/barAndCafe/src/openTripMaps.ts @@ -58,6 +58,28 @@ async function callCity(name:string) { } } +/** + * make GET request to the OTM for city info. + * @param {string} name Name of a city + * @returns {Geoname} info of a search city their name, country, lat, lon, etc. (cf: [opentripmap](https://dev.opentripmap.org/docs#)) + */ +async function callId(id:string) { + const optionsId = { + method: 'GET', + url: 'https://api.opentripmap.com/0.1/en/places/xid/' + id, + params: { + apikey: key + }, + headers: {'Content-Type': 'application/json'} + }; + + try { + const { data } = await axios.request(optionsId); + return data + } catch (error) { + console.error(error); + } +} /** * Handle GET request for city search route ('/otm/city'). @@ -99,5 +121,19 @@ export async function getRadius(req:express.Request, res: express.Response) { res.send( await callRadius(lon,lat,radius as string)) } +/** + * Handle GET request for radius search route ('/otm/radius'). + * @param {express.Request} req - HTTP Request object. + * @param {express.Response} res - HTTP Response object. + */ +export async function getPoiId(req: express.Request, res: express.Response){ + const id = req.query["id"] as string + if(!id){ + res.status(400).send("Missing Argument name") + return + } + res.send( await callId( id as string)) +} + //TODO: fair une route ou l'on donne l'id un établicement pour avoir des détailles //TODO: fair une route ou l'on donne 2 coordonée