add call otm call

This commit is contained in:
Clement 2024-05-18 13:04:43 +02:00
parent 165b2e91bf
commit 9ac4ba7252

View File

@ -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'). * 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)) 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 l'id un établicement pour avoir des détailles
//TODO: fair une route ou l'on donne 2 coordonée //TODO: fair une route ou l'on donne 2 coordonée