Compare commits

...

4 Commits

Author SHA1 Message Date
ae9e1eae47 add route and swagger doc
All checks were successful
Build Docker Image Front / run (pull_request) Successful in 27s
Build Docker Image Back / run (pull_request) Successful in 44s
JsDocs / coverage (pull_request) Successful in 37s
Test and coverage / coverage (pull_request) Successful in 1m16s
2024-05-18 13:04:59 +02:00
9ac4ba7252 add call otm call 2024-05-18 13:04:43 +02:00
165b2e91bf add some bruno test 2024-05-18 13:04:23 +02:00
a05fb87f85 add test for detaill POI 2024-05-18 13:04:12 +02:00
5 changed files with 145 additions and 1 deletions

View File

@ -1,4 +1,4 @@
import { getCity, getRadius } from "./openTripMaps"
import { getCity, getRadius, getPoiId } from "./openTripMaps"
import express from "express"
/**
* Initialize Express application instance.
@ -91,4 +91,28 @@ app.get("/otm/city", getCity)
*/
app.get("/otm/radius", getRadius)
/**
* @openapi
* /otm/poidetaill:
* get:
* summary: detail of a POI
* description: detail of a POI link name, kind, rate,...
* parameters:
* - name: id
* in: query
* required: true
* description: Unique identifier of the object in OpenTripMap
* schema:
* type: string
* responses:
* 200:
* description: Return a list of bars and coffee in city in geoJSON format
* 400:
* description: Missing Argument Error
* 401:
* description: Missing OTM tocken
*/
app.get("/otm/poidetaill", getPoiId)
export default app

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').
@ -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

View File

@ -108,4 +108,62 @@ describe("Test the otm city path", () => {
});
})
test("It should response the 200 code for GET method", done => {
request(app)
.get("/otm/poidetaill")
.query({'id':'562635'})
.then(response => {
expect(response.statusCode).toBe(200);
done();
});
});
test("Get bar in radius from API", done => {
const out = {
"xid": "N4032296324",
"name": "Le 27 point carré",
"address": {
"road": "Rue Raymond Poincaré",
"town": "La Roche-sur-Yon",
"state": "Pays de la Loire",
"county": "La Roche-sur-Yon",
"suburb": "Zola",
"country": "France",
"postcode": "85000",
"country_code": "fr",
"house_number": "27",
"neighbourhood": "Cité des Forges"
},
"rate": "1",
"osm": "node/4032296324",
"kinds": "foods,bars,tourist_facilities",
"sources": {
"geometry": "osm",
"attributes": [
"osm"
]
},
"otm": "https://opentripmap.com/en/card/N4032296324",
"point": {
"lon": -1.4344594478607178,
"lat": 46.66864776611328
}
}
request(app)
.get("/otm/poidetaill")
.query({'id':'562635'})
.then(response => {
expect(response.text).toEqual(JSON.stringify(out));
done();
});
})
test("It should response the 200 code for GET method", done => {
request(app)
.get("/otm/poidetaill")
.then(response => {
expect(response.statusCode).toBe(400);
done();
});
});
});

View File

@ -0,0 +1,11 @@
meta {
name: get return format
type: http
seq: 11
}
get {
url: https://dev.opentripmap.org/openapi.en.json
body: none
auth: none
}

View File

@ -0,0 +1,15 @@
meta {
name: otm_ex_drink_id
type: http
seq: 10
}
get {
url: https://api.opentripmap.com/0.1/en/places/xid/562635?apikey={{OTM_KEY}}
body: none
auth: none
}
query {
apikey: {{OTM_KEY}}
}