Skip to content

Commit eac217f

Browse files
committed
feat: added GetDeployInformationUseCase
1 parent 779f9ee commit eac217f

4 files changed

Lines changed: 69 additions & 1 deletion

File tree

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/**
2+
* @license
3+
* Copyright CERN and copyright holders of ALICE O2. This software is
4+
* distributed under the terms of the GNU General Public License v3 (GPL
5+
* Version 3), copied verbatim in the file "COPYING".
6+
*
7+
* See http://alice-o2.web.cern.ch/license for full licensing information.
8+
*
9+
* In applying this license CERN does not waive the privileges and immunities
10+
* granted to it by virtue of its status as an Intergovernmental Organization
11+
* or submit itself to any jurisdiction.
12+
*/
13+
14+
const { IUseCase } = require('../../interfaces');
15+
16+
const START_TIME = new Date();
17+
18+
/**
19+
* GetDeployInformationUseCase
20+
*/
21+
class GetDeployInformationUseCase extends IUseCase {
22+
/**
23+
* Executes this use case.
24+
*
25+
* @returns {Promise} Promise object represents the result of this use case.
26+
*/
27+
async execute() {
28+
return Promise.resolve({
29+
age: Math.round((new Date() - START_TIME) / 1000),
30+
start: START_TIME.getTime(),
31+
});
32+
}
33+
}
34+
35+
module.exports = GetDeployInformationUseCase;

lib/application/usecases/server/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@
1111
* or submit itself to any jurisdiction.
1212
*/
1313

14+
const GetDeployInformationUseCase = require('./GetDeployInformationUseCase');
1415
const GetServerInformationUseCase = require('./GetServerInformationUseCase');
1516

1617
module.exports = {
18+
GetDeployInformationUseCase,
1719
GetServerInformationUseCase,
1820
};

lib/server/controllers/home.controller.js

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* or submit itself to any jurisdiction.
1212
*/
1313

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

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

39+
/**
40+
* Basic deploy information controller.
41+
*
42+
* @param {Object} request The *request* object represents the HTTP request and has properties for the request query
43+
* string, parameters, body, HTTP headers, and so on.
44+
* @param {Object} response The *response* object represents the HTTP response that an Express app sends when it gets an
45+
* HTTP request.
46+
* @param {Function} next The *next* object represents the next middleware function which is used to pass control to the
47+
* next middleware function.
48+
* @returns {undefined}
49+
*/
50+
const getDeployInfo = async (request, response, next) => {
51+
let deployInfo;
52+
try {
53+
deployInfo = await new GetDeployInformationUseCase().execute();
54+
} catch (error) {
55+
next(error);
56+
return;
57+
}
58+
59+
response.status(200).json(deployInfo);
60+
};
61+
3962
module.exports = {
63+
getDeployInfo,
4064
getServerInfo,
4165
};

lib/server/routers/home.router.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,11 @@ module.exports = {
1818
path: '/',
1919
controller: HomeController.getServerInfo,
2020
args: { public: true },
21+
children: [
22+
{
23+
method: 'get',
24+
path: 'status',
25+
controller: HomeController.getDeployInfo,
26+
},
27+
],
2128
};

0 commit comments

Comments
 (0)