diff --git a/app.js b/app.js index b7d4104..2fb9c3e 100644 --- a/app.js +++ b/app.js @@ -30,6 +30,8 @@ const statRtr = require('./src/routes/stats.routes'); const regRtr = require('./src/routes/registration.routes'); const pisRtr = require('./src/routes/pis.routes'); const trainRtr = require('./src/routes/train.routes'); +const pis2Rtr = require('./src/routes/pis2.routes'); // API Version 2 Routes +const miscRtr = require('./src/routes/misc.routes'); // Non-Public API Routes // Set Server Configurations const srvListen = process.env.OWL_SRV_LISTEN || '0.0.0.0'; @@ -70,6 +72,10 @@ app.use(express.json()); //JSON Parsing for POST Requests app.use(compression()); // Compress API Data if supported by client app.use(limiter); +// 2023 Rationalisation Routes (/api/v2, /misc) +app.use('/api/v2/pis', pis2Rtr); // API Version 2 Routes +app.use('/misc', miscRtr); // Non public-api endpoints (Stats, Issue, etc.) + // Unauthenticated Routes app.use('/api/v1/list', listRtr); app.use('/api/v1/ldb', ldbRtr); diff --git a/src/controllers/pis.controllers.js b/src/controllers/pis.controllers.js index 46f33f9..3ca125b 100644 --- a/src/controllers/pis.controllers.js +++ b/src/controllers/pis.controllers.js @@ -11,6 +11,19 @@ async function byOrigDest(req, res, next){ } } +/* Used in /api/v2 */ +async function byStartEndCRS(req, res, next){ + try { + let startCrs = req.params.startCrs; + let endCrs = req.params.endCrs; + res.json(await pis.findPisByOrigDest(startCrs,endCrs)); + } catch (err) { + console.error('Unknown Error', err.message); + next(err); + } +} + +/* Used in /api/v2 */ async function byCode(req, res, next){ try { let code = req.params.code; @@ -33,6 +46,7 @@ async function random(req, res, next){ module.exports = { byOrigDest, + byStartEndCRS, byCode, random }; \ No newline at end of file diff --git a/src/routes/api1.routes.js b/src/routes/api1.routes.js new file mode 100644 index 0000000..e37032e --- /dev/null +++ b/src/routes/api1.routes.js @@ -0,0 +1,9 @@ +const express = require('express'); +const router = express.Router(); + +// Controller Imports + + +// Routes + +module.exports = router; \ No newline at end of file diff --git a/src/routes/api2.routes.js b/src/routes/api2.routes.js new file mode 100644 index 0000000..aa84695 --- /dev/null +++ b/src/routes/api2.routes.js @@ -0,0 +1,34 @@ +const express = require('express'); +const router = express.Router(); + +/* Controller Imports */ + +// Live + +// Timetable + + + +// Ref + +// User + +/* Routes */ + +// Live +router.get('/live/station/:id/:type'); +router.get('/live/train/:searchType/:id'); + +// Timetable +router.get('/timetable/train/:date/:searchType/:id'); + +// Ref +router.get('/reasonCode/:code'); +router.get('/locationCode/:searchType/:id'); + +// User +router.post('/user'); +router.get('/user/:uuid'); +router.delete('/user/:uuid'); + +module.exports = router; \ No newline at end of file diff --git a/src/routes/misc.routes.js b/src/routes/misc.routes.js new file mode 100644 index 0000000..ded3fbf --- /dev/null +++ b/src/routes/misc.routes.js @@ -0,0 +1,14 @@ +const express = require('express'); +const router = express.Router(); + +// Controller Imports + + +// Routes + +router.get('/server/stats'); +router.get('/server/versions'); + +router.post('issue'); + +module.exports = router; \ No newline at end of file diff --git a/src/routes/pis2.routes.js b/src/routes/pis2.routes.js new file mode 100644 index 0000000..c883295 --- /dev/null +++ b/src/routes/pis2.routes.js @@ -0,0 +1,9 @@ +const express = require('express'); +const router = express.Router(); +const pisCtr = require('../controllers/pis.controllers'); + +// PIS +router.get('/byCode/:code', pisCtr.byCode); +router.get('/:startCrs/:endCrs', pisCtr.byStartEndCRS); + +module.exports = router; \ No newline at end of file