Commit 3057227d authored by Adrien Pavie's avatar Adrien Pavie
Browse files

Added route for summary retrieval (closes #4)

parent 68e04100
......@@ -145,3 +145,54 @@ exports.searchBbox = function(req, res) {
exports.fetchers = function(req, res) {
res.json({ "status": "OK", "fetchers": (new P4C.PicturesManager()).getFetcherDetails() });
};
/**
* @api {get} /summary/bbox Bounding box
* @apiDescription Retrieve a summary of pictures availability in a given area
* @apiName GetSummaryBbox
* @apiGroup Summary
*
* @apiParam {Number} south The minimal latitude (WGS84)
* @apiParam {Number} west The minimal longitude (WGS84)
* @apiParam {Number} north The maximal latitude (WGS84)
* @apiParam {Number} east The maximal longitude (WGS84)
* @apiParam {Long} [mindate] The minimum timestamp for a given time range, in milliseconds since 1st january 1970 (Epoch)
* @apiParam {Long} [maxdate] The maximum timestamp for a given time range, in milliseconds since 1st january 1970 (Epoch)
*
* @apiSuccess {String} status The response status (OK)
* @apiSuccess {Object} summary The summary of pictures availability
* @apiSuccess {int} summary.amount How many pictures are available in the area
* @apiSuccess {int} summary.last The last picture timestamp, in milliseconds since 1st january 1970 (Epoch)
* @apiSuccess {boolean} summary.approxAmount Is the returned amount approximated or not
*/
exports.summaryBbox = function(req, res) {
/*console.log("[SUMMARY] BBox "
* +req.query.south+", "+req.query.west+", "+req.query.north+", "+req.query.east
* +" between TS "
* +req.query.mindate+" and "+req.query.maxdate;*/
const picManager = new P4C.PicturesManager({ fetcherCredentials: CREDENTIALS });
//Prepare event for when summary is ready
picManager.on("summaryready", function(summary) {
res.json({ "status": "OK", "summary": summary });
});
picManager.on("fetcherfailed", function(fetcherId) {
console.log("[SUMMARY] Failed on fetcher "+fetcherId);
});
//Call for pictures download
try {
picManager.startSummaryRetrieval(
new P4C.LatLngBounds(new P4C.LatLng(req.query.south, req.query.west), new P4C.LatLng(req.query.north, req.query.east)),
{
mindate: req.query.mindate ? parseInt(req.query.mindate) : undefined,
maxdate: req.query.maxdate ? parseInt(req.query.maxdate) : undefined
}
);
}
catch(e) {
res.status(500).send({ "status": "NOTOK", "error": e.toString() });
}
};
......@@ -32,4 +32,10 @@ module.exports = function(app) {
app.route('/fetchers')
.get(ctrl.fetchers);
app.route('/summary')
.get(ctrl.default);
app.route('/summary/bbox')
.get(ctrl.summaryBbox);
};
......@@ -208,5 +208,105 @@ define({ "api": [
"version": "0.0.0",
"filename": "api/controllers/P4CaaSController.js",
"groupTitle": "Search"
},
{
"type": "get",
"url": "/summary/bbox",
"title": "Bounding box",
"description": "<p>Retrieve a summary of pictures availability in a given area</p>",
"name": "GetSummaryBbox",
"group": "Summary",
"parameter": {
"fields": {
"Parameter": [
{
"group": "Parameter",
"type": "Number",
"optional": false,
"field": "south",
"description": "<p>The minimal latitude (WGS84)</p>"
},
{
"group": "Parameter",
"type": "Number",
"optional": false,
"field": "west",
"description": "<p>The minimal longitude (WGS84)</p>"
},
{
"group": "Parameter",
"type": "Number",
"optional": false,
"field": "north",
"description": "<p>The maximal latitude (WGS84)</p>"
},
{
"group": "Parameter",
"type": "Number",
"optional": false,
"field": "east",
"description": "<p>The maximal longitude (WGS84)</p>"
},
{
"group": "Parameter",
"type": "Long",
"optional": true,
"field": "mindate",
"description": "<p>The minimum timestamp for a given time range, in milliseconds since 1st january 1970 (Epoch)</p>"
},
{
"group": "Parameter",
"type": "Long",
"optional": true,
"field": "maxdate",
"description": "<p>The maximum timestamp for a given time range, in milliseconds since 1st january 1970 (Epoch)</p>"
}
]
}
},
"success": {
"fields": {
"Success 200": [
{
"group": "Success 200",
"type": "String",
"optional": false,
"field": "status",
"description": "<p>The response status (OK)</p>"
},
{
"group": "Success 200",
"type": "Object",
"optional": false,
"field": "summary",
"description": "<p>The summary of pictures availability</p>"
},
{
"group": "Success 200",
"type": "int",
"optional": false,
"field": "summary.amount",
"description": "<p>How many pictures are available in the area</p>"
},
{
"group": "Success 200",
"type": "int",
"optional": false,
"field": "summary.last",
"description": "<p>The last picture timestamp, in milliseconds since 1st january 1970 (Epoch)</p>"
},
{
"group": "Success 200",
"type": "boolean",
"optional": false,
"field": "summary.approxAmount",
"description": "<p>Is the returned amount approximated or not</p>"
}
]
}
},
"version": "0.0.0",
"filename": "api/controllers/P4CaaSController.js",
"groupTitle": "Summary"
}
] });
......@@ -208,5 +208,105 @@
"version": "0.0.0",
"filename": "api/controllers/P4CaaSController.js",
"groupTitle": "Search"
},
{
"type": "get",
"url": "/summary/bbox",
"title": "Bounding box",
"description": "<p>Retrieve a summary of pictures availability in a given area</p>",
"name": "GetSummaryBbox",
"group": "Summary",
"parameter": {
"fields": {
"Parameter": [
{
"group": "Parameter",
"type": "Number",
"optional": false,
"field": "south",
"description": "<p>The minimal latitude (WGS84)</p>"
},
{
"group": "Parameter",
"type": "Number",
"optional": false,
"field": "west",
"description": "<p>The minimal longitude (WGS84)</p>"
},
{
"group": "Parameter",
"type": "Number",
"optional": false,
"field": "north",
"description": "<p>The maximal latitude (WGS84)</p>"
},
{
"group": "Parameter",
"type": "Number",
"optional": false,
"field": "east",
"description": "<p>The maximal longitude (WGS84)</p>"
},
{
"group": "Parameter",
"type": "Long",
"optional": true,
"field": "mindate",
"description": "<p>The minimum timestamp for a given time range, in milliseconds since 1st january 1970 (Epoch)</p>"
},
{
"group": "Parameter",
"type": "Long",
"optional": true,
"field": "maxdate",
"description": "<p>The maximum timestamp for a given time range, in milliseconds since 1st january 1970 (Epoch)</p>"
}
]
}
},
"success": {
"fields": {
"Success 200": [
{
"group": "Success 200",
"type": "String",
"optional": false,
"field": "status",
"description": "<p>The response status (OK)</p>"
},
{
"group": "Success 200",
"type": "Object",
"optional": false,
"field": "summary",
"description": "<p>The summary of pictures availability</p>"
},
{
"group": "Success 200",
"type": "int",
"optional": false,
"field": "summary.amount",
"description": "<p>How many pictures are available in the area</p>"
},
{
"group": "Success 200",
"type": "int",
"optional": false,
"field": "summary.last",
"description": "<p>The last picture timestamp, in milliseconds since 1st january 1970 (Epoch)</p>"
},
{
"group": "Success 200",
"type": "boolean",
"optional": false,
"field": "summary.approxAmount",
"description": "<p>Is the returned amount approximated or not</p>"
}
]
}
},
"version": "0.0.0",
"filename": "api/controllers/P4CaaSController.js",
"groupTitle": "Summary"
}
]
......@@ -8,7 +8,7 @@ define({
"apidoc": "0.3.0",
"generator": {
"name": "apidoc",
"time": "2017-06-15T10:31:52.352Z",
"time": "2017-06-15T19:51:13.398Z",
"url": "http://apidocjs.com",
"version": "0.17.6"
}
......
......@@ -8,7 +8,7 @@
"apidoc": "0.3.0",
"generator": {
"name": "apidoc",
"time": "2017-06-15T10:31:52.352Z",
"time": "2017-06-15T19:51:13.398Z",
"url": "http://apidocjs.com",
"version": "0.17.6"
}
......
......@@ -227,4 +227,50 @@ describe('Server routes', function() {
});
});
});
describe('/summary/bbox', function() {
it("should return NOTOK on GET without parameters", function(done){
request(server)
.get("/summary/bbox")
.expect("Content-type",/json/)
.expect(500)
.end(function(err, res){
assert.equal(res.status, 500);
assert.equal(res.body.status, "NOTOK");
done();
});
});
it("should return summary on GET with BBox only", function(done){
request(server)
.get("/summary/bbox?west=-1.69&south=48.125&east=-1.685&north=48.13")
.expect("Content-type",/json/)
.expect(200)
.end(function(err, res){
assert.equal(res.status, 200);
assert.equal(res.body.status, "OK");
assert.ok(res.body.summary !== undefined);
assert.ok(!isNaN(res.body.summary.amount));
assert.ok(!isNaN(res.body.summary.last));
assert.ok(res.body.summary.approxAmount === true || res.body.summary.approxAmount === false);
done();
});
}).timeout(10000);
it("should return summary on GET with BBox and time range", function(done){
request(server)
.get("/summary/bbox?west=-1.69&south=48.125&east=-1.685&north=48.13&mindate=1483228800000&maxdate=1485907200000")
.expect("Content-type",/json/)
.expect(200)
.end(function(err, res){
assert.equal(res.status, 200);
assert.equal(res.body.status, "OK");
assert.ok(res.body.summary !== undefined);
assert.equal(res.body.summary.amount, 36);
assert.ok(res.body.summary.last >= 1483228800000 && res.body.summary.last <= 1485907200000);
assert.equal(res.body.summary.approxAmount, false);
done();
});
}).timeout(10000);
});
});
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment