aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorjw2552018-01-16 17:33:58 +0000
committerjw2552018-01-16 17:33:58 +0000
commit4cd8de869d493d95343ee09a186ac94ef6ce2bf4 (patch)
tree1e33914f48f222992a8ba2332fdd984c741fe0a4 /src
parentupdated readme, todo to explain/include changes. wrote a test for helloworld.... (diff)
downloadmedicine-4cd8de869d493d95343ee09a186ac94ef6ce2bf4.tar.gz
medicine-4cd8de869d493d95343ee09a186ac94ef6ce2bf4.zip

added router class to handle API calls and updated TODO with latest Protocol decisions available

Diffstat (limited to 'src')
-rw-r--r--src/FileRouter.ts57
-rw-r--r--src/app.ts12
2 files changed, 65 insertions, 4 deletions
diff --git a/src/FileRouter.ts b/src/FileRouter.ts
new file mode 100644
index 0000000..789a068
--- /dev/null
+++ b/src/FileRouter.ts
@@ -0,0 +1,57 @@
+import {Router, Request, Response, NextFunction} from 'express';
+const Files = null;//require('../data');
+
+
+/*
+ * |->
+ * /project/files/directory/file?filters
+ * |->
+ */
+export class FileRouter {
+ router: Router
+
+ /**
+ * Initialize the FileRouter
+ */
+ constructor() {
+ this.router = Router();
+ this.init();
+ }
+
+ /**
+ * GET a File.
+ */
+ public getFile(req: Request, res: Response, next: NextFunction) {
+ let fileID = req.params.file;
+ // check if fileID is number or path
+ // find file in data
+
+ // check if only metadata was requested and return appropriate info
+ // otherwise:
+
+ // if image:
+ // convert if necessary
+ // zoom if necessary
+
+ // if csv/xls
+ // send data in appropriate csv format
+ // limit cols if necessary
+
+ res.send("File");
+ }
+
+ /**
+ * Take each handler, and attach to one of the Express.Router's
+ * endpoints.
+ */
+ init() {
+ this.router.get('/:file', this.getFile);
+ }
+
+}
+
+// Create the FileRouter, and export its configured Express.Router
+const fileRoutes = new FileRouter();
+fileRoutes.init();
+
+export default fileRoutes.router;
diff --git a/src/app.ts b/src/app.ts
index 345b73f..01e35fc 100644
--- a/src/app.ts
+++ b/src/app.ts
@@ -1,6 +1,8 @@
import * as express from 'express';
import * as logger from 'morgan';
import * as bodyParser from 'body-parser';
+import FileRouter from './FileRouter';
+
class App {
public express
@@ -18,14 +20,16 @@ class App {
this.express.use(bodyParser.urlencoded({ extended: false }));
}
+ // Configure API endpoints.
private mountRoutes (): void {
- const router = express.Router()
- router.get('/', (req, res) => {
+ const defRouter = express.Router()
+ defRouter.get('/', (req, res) => {
res.json({
- message: 'Hello World!'
+ message: 'Welcome to the CS3099 BE4 server!'
})
})
- this.express.use('/', router)
+ this.express.use('/', defRouter)
+ this.express.use('/cs3099group-be-4/files/directory', FileRouter)
}
}