From 121528c413e7b4dbc09a235426f1541db2632a35 Mon Sep 17 00:00:00 2001 From: Fred Boniface Date: Fri, 21 Apr 2023 21:28:13 +0100 Subject: [PATCH] implement /pis endpoint Signed-off-by: Fred Boniface --- app.js | 2 ++ src/controllers/pis.controllers.js | 17 +++++++++++++++++ src/routes/pis.routes.js | 7 +++++++ 3 files changed, 26 insertions(+) create mode 100644 src/controllers/pis.controllers.js create mode 100644 src/routes/pis.routes.js diff --git a/app.js b/app.js index 3303e8b..caa74ec 100644 --- a/app.js +++ b/app.js @@ -26,6 +26,7 @@ const findRtr = require('./src/routes/find.routes'); // /find endpoint const issueRtr = require('./src/routes/issue.routes'); // /issue endpoints const statRtr = require('./src/routes/stats.routes'); // /stat endpoints const regRtr = require('./src/routes/registration.routes'); // /registration endpoints +const pisRtr = require('./src/routes/pis.routes'); // /pis endpoints // Set Server Configurations const srvListen = process.env.OWL_SRV_LISTEN || "0.0.0.0" @@ -72,6 +73,7 @@ app.use('/api/v1/find', findRtr); app.use('/api/v1/issue', issueRtr); app.use('/api/v1/stats', statRtr); app.use('/api/v1/register', regRtr); +app.use('/api/v1/pis', pisRtr) // Authented Routes app.use('/api/v1/ldbs', authenticate) diff --git a/src/controllers/pis.controllers.js b/src/controllers/pis.controllers.js new file mode 100644 index 0000000..3971837 --- /dev/null +++ b/src/controllers/pis.controllers.js @@ -0,0 +1,17 @@ +const pis = require('../services/pis.services'); + +async function byOrigDest(req, res, next){ + try { + let start = req.params.start + let end = req.params.end + res.json(await pis.findPisByOrigDest(start,end)) + } catch (err) { + console.error(`Unknown Error`, err.message); + next(err); + } +} + + +module.exports = { + byOrigDest +} \ No newline at end of file diff --git a/src/routes/pis.routes.js b/src/routes/pis.routes.js new file mode 100644 index 0000000..70fa609 --- /dev/null +++ b/src/routes/pis.routes.js @@ -0,0 +1,7 @@ +const express = require('express'); +const router = express.Router(); +const pisController = require('../controllers/pis.controllers'); + +router.get('/origdest/:start/:end', pisController.byOrigDest); + +module.exports = router; \ No newline at end of file