Skip to content

Commit

Permalink
feat: added GetDeployInformationUseCase
Browse files Browse the repository at this point in the history
  • Loading branch information
mvegter committed May 1, 2020
1 parent 779f9ee commit eac217f
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 1 deletion.
35 changes: 35 additions & 0 deletions lib/application/usecases/server/GetDeployInformationUseCase.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* @license
* Copyright CERN and copyright holders of ALICE O2. This software is
* distributed under the terms of the GNU General Public License v3 (GPL
* Version 3), copied verbatim in the file "COPYING".
*
* See http://alice-o2.web.cern.ch/license for full licensing information.
*
* In applying this license CERN does not waive the privileges and immunities
* granted to it by virtue of its status as an Intergovernmental Organization
* or submit itself to any jurisdiction.
*/

const { IUseCase } = require('../../interfaces');

const START_TIME = new Date();

/**
* GetDeployInformationUseCase
*/
class GetDeployInformationUseCase extends IUseCase {
/**
* Executes this use case.
*
* @returns {Promise} Promise object represents the result of this use case.
*/
async execute() {
return Promise.resolve({
age: Math.round((new Date() - START_TIME) / 1000),
start: START_TIME.getTime(),
});
}
}

module.exports = GetDeployInformationUseCase;
2 changes: 2 additions & 0 deletions lib/application/usecases/server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
* or submit itself to any jurisdiction.
*/

const GetDeployInformationUseCase = require('./GetDeployInformationUseCase');
const GetServerInformationUseCase = require('./GetServerInformationUseCase');

module.exports = {
GetDeployInformationUseCase,
GetServerInformationUseCase,
};
26 changes: 25 additions & 1 deletion lib/server/controllers/home.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* or submit itself to any jurisdiction.
*/

const { server: { GetServerInformationUseCase } } = require('../../application/usecases');
const { server: { GetDeployInformationUseCase, GetServerInformationUseCase } } = require('../../application/usecases');

/**
* Basic api information controller.
Expand All @@ -36,6 +36,30 @@ const getServerInfo = async (request, response, next) => {
response.status(200).json(serverInfo);
};

/**
* Basic deploy information controller.
*
* @param {Object} request The *request* object represents the HTTP request and has properties for the request query
* string, parameters, body, HTTP headers, and so on.
* @param {Object} response The *response* object represents the HTTP response that an Express app sends when it gets an
* HTTP request.
* @param {Function} next The *next* object represents the next middleware function which is used to pass control to the
* next middleware function.
* @returns {undefined}
*/
const getDeployInfo = async (request, response, next) => {
let deployInfo;
try {
deployInfo = await new GetDeployInformationUseCase().execute();
} catch (error) {
next(error);
return;
}

response.status(200).json(deployInfo);
};

module.exports = {
getDeployInfo,
getServerInfo,
};
7 changes: 7 additions & 0 deletions lib/server/routers/home.router.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,11 @@ module.exports = {
path: '/',
controller: HomeController.getServerInfo,
args: { public: true },
children: [
{
method: 'get',
path: 'status',
controller: HomeController.getDeployInfo,
},
],
};

0 comments on commit eac217f

Please sign in to comment.