diff --git a/README.md b/README.md index 5dcdab3..80158a9 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,9 @@ Whilst the application is open source, the webservice (owlboard.fb-infra.uk) is - Returns JSON: `{"STATION NAME":{"CRS":"code","TIPLOC":"code"}}` - /ldb: + - /{crs}: + - GET: Get departure board for {crs} + - Returns JSON: Formatted as per ldb-json module.SS ## Stack: - app.js -> Launches server, Entry Point, defines routers and middlewares. diff --git a/app.js b/app.js index 4a9e603..2330922 100644 --- a/app.js +++ b/app.js @@ -10,6 +10,7 @@ const config = require('./src/configs/server.configs'); const version = require('./src/configs/version.configs'); const testRtr = require('./src/routes/test.routes'); const listRtr = require('./src/routes/list.routes'); +const ldbRtr = require('./src/routes/ldb.routes'); // Print version number: console.log(`Starting OwlBoard - App Version: ${version.app} - API versions: ${version.api}`); @@ -29,6 +30,7 @@ app.use(express.static('static')); //Serve static content from static // Express Routes app.use('/api/v1/test', testRtr); app.use('/api/v1/list', listRtr); +app.use('/api/v1/ldb', ldbRtr); // Start Express app.listen(config.port, config.listen, (error) =>{ diff --git a/src/controllers/ldb.controllers.js b/src/controllers/ldb.controllers.js new file mode 100644 index 0000000..2c6917e --- /dev/null +++ b/src/controllers/ldb.controllers.js @@ -0,0 +1,15 @@ +const ldb = require('../services/ldb.services'); + +async function get(req, res, next){ + try { + var id = req.params.id + res.json(await ldb.get(req.body, id)) + } catch (err) { + console.error(`Unknown Error`, err.message); + next(err); + } +} + +module.exports = { + get +} \ No newline at end of file diff --git a/src/routes/ldb.routes.js b/src/routes/ldb.routes.js index e69de29..591bd45 100644 --- a/src/routes/ldb.routes.js +++ b/src/routes/ldb.routes.js @@ -0,0 +1,19 @@ +const express = require('express'); +const router = express.Router(); +const ldbController = require('../controllers/ldb.controllers'); + +/* GET programming languages. */ +//router.get('/', programmingLanguagesController.get); + +/* POST programming language */ +//router.post('/', programmingLanguagesController.create); + +/* PUT programming language */ +//router.put('/:id', programmingLanguagesController.update); + +/* DELETE programming language */ +//router.delete('/:id', programmingLanguagesController.remove); + +router.get('/:id', ldbController.get); + +module.exports = router; \ No newline at end of file diff --git a/src/services/ldb.services.js b/src/services/ldb.services.js index 1e44c40..04bf4c2 100644 --- a/src/services/ldb.services.js +++ b/src/services/ldb.services.js @@ -1,28 +1,30 @@ // Parse and return an LDB Request // FUNCTIONS -// findBoard(input, staff): Exported: - // input: [str, CRS or TIPLOC, staff: BOOL, use staff API or not] - // Runs checks on input data and calls an internal function to get data. +// post(body, id): Exported: + // body: [req.body from controller] + // id : [req.params.id from controller - this is expected to be CRS or TIPLOC] // convertTiploc(TIPLOC) : Exported: Looks up CRS, Name & STANOX for Tiploc const ldb = require('ldbs-json') const keys = require('/srv/keys/owlboard/keys.configs') +const util = require('../utils/ldb.utils') -async function findBoard(input, staff){ - // Check whether input is CRS or TIPLOC +async function get(body, id){ + // Read request body for information on request + // Check whether input is CRS or TIPLOC with util.checkInput(input) // if TIPLOC then convert to CRS, // then check whether staff is true or false, // then call the correct function and // return that output to calling function - // for now, just call arrDepBoard(CRS) - var output = await arrDepBoard(input) + // for now, just call arrDepBoard(CRS) with the id from the url directly used - UNSAFE + var output = await arrDepBoard(id) return output } async function arrDepBoard(CRS){ - var valid = await checkCrs(CRS) + var valid = await util.checkCrs(CRS) if (valid != false){ var options = { numRows: 10, @@ -36,18 +38,6 @@ async function arrDepBoard(CRS){ } }; -async function checkCrs(input){ - // Check whether CRS is valid - // Until implemented always return true - return true -} - -async function convertTiploc(TIPLOC){ - // Convert TIPLOC to CRS with DBLookup - return TIPLOC -} - module.exports = { - convertTiploc, - findBoard + get } \ No newline at end of file diff --git a/src/utils/ldb.utils.js b/src/utils/ldb.utils.js new file mode 100644 index 0000000..61e7f53 --- /dev/null +++ b/src/utils/ldb.utils.js @@ -0,0 +1,16 @@ +async function checkCrs(input){ + // Check whether CRS is valid + // if not, try to get tiploc + // Until implemented always return true + return true +} + +async function convertTiploc(input){ + // Convert TIPLOC to CRS with DBLookup + return input +} + +module.exports = { + checkCrs, + convertTiploc +} \ No newline at end of file