'use strict';
const Koa = require('koa');
+const KoaBodyParser = require('koa-bodyparser');
const KoaRoute = require('koa-route');
+const MainMenuController = require('./controllers/main_menu');
+const RecordingMenuController = require('./controllers/recording_menu');
+const RecordingsController = require('./controllers/recordings');
+
const internals = {};
/**
this._app = Koa();
- this._app.use(KoaRoute.get('/menus/main', function * () {
-
- this.body = 'I will return the main menu.';
- }));
-
- this._app.use(KoaRoute.post('/menus/main', function * () {
+ this._app.use(KoaBodyParser());
- this.body = 'I will parse the main menu.';
- }));
+ this._initializeMainMenuRoutes();
+ this._initializeRecordingMenuRoutes();
+ this._initializeRecordingsRoutes();
- this._app.use(KoaRoute.get('/menus/recording', function * () {
+ this._app.use(function * () {
- this.body = 'I will return the select recording menu.';
- }));
+ this.body = 'How did you get here? Shoo!';
+ });
- this._app.use(KoaRoute.post('/menus/recording', function * () {
+ }
- this.body = 'I will parse the select recording menu.';
- }));
+ // Starts listening
- this._app.use(KoaRoute.get('/recordings', function * () {
+ _startServer() {
- this.body = 'I will initiate recording process';
- }));
+ this._app.listen(this.port);
+ }
- this._app.use(KoaRoute.post('/recordings', function * () {
+ // Initializes the main menu routes.
- this.body = 'I will create a new recording';
- }));
+ _initializeMainMenuRoutes() {
- this._app.use(KoaRoute.get('/recordings/:id', function * (id) {
+ const mainMenuController = new MainMenuController();
- id = parseInt(id);
+ this._app.use(KoaRoute.get('/menus/main', mainMenuController.serveMenu()));
+ this._app.use(KoaRoute.post('/menus/main', mainMenuController.parseMenuSelection()));
+ }
- if (id === 0) {
- this.body = 'I will return a random recording';
- }
- else {
- this.body = 'I will return a specific recording';
- }
- }));
+ // Initializes the recording menu routes.
- this._app.use(function * () {
+ _initializeRecordingMenuRoutes() {
- this.body = 'hello, world';
- });
+ const recordingMenuController = new RecordingMenuController();
+ this._app.use(KoaRoute.get('/menus/recording', recordingMenuController.serveMenu()));
+ this._app.use(KoaRoute.post('/menus/recording', recordingMenuController.parseMenuSelection()));
}
- // Starts listening
+ // Initializes the recordings routes.
- _startServer() {
+ _initializeRecordingsRoutes() {
- this._app.listen(this.port);
+ const recordingsController = new RecordingsController({
+ redis: this.redis
+ });
+
+ this._app.use(KoaRoute.get('/recordings', recordingsController.startRecording()));
+ this._app.use(KoaRoute.post('/recordings', recordingsController.saveRecording()));
+ this._app.use(KoaRoute.get('/recordings/:id', recordingsController.getRecording()));
}
// Prints the banner.