/api/v2/pis Ready to go

Signed-off-by: Fred Boniface <fred@fjla.uk>
This commit is contained in:
Fred Boniface 2023-06-17 22:14:58 +01:00
parent 06259e3d9f
commit a04570c9e4
6 changed files with 86 additions and 0 deletions

6
app.js
View File

@ -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);

View File

@ -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
};

View File

@ -0,0 +1,9 @@
const express = require('express');
const router = express.Router();
// Controller Imports
// Routes
module.exports = router;

34
src/routes/api2.routes.js Normal file
View File

@ -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;

14
src/routes/misc.routes.js Normal file
View File

@ -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;

View File

@ -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;