-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added GET /api/subystems endpoint
- Loading branch information
Showing
19 changed files
with
578 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/** | ||
* @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. | ||
*/ | ||
|
||
/** | ||
* SubsystemAdapter | ||
*/ | ||
class SubsystemAdapter { | ||
/** | ||
* Converts the given database object to an entity object. | ||
* | ||
* @param {Object} databaseObject Object to convert. | ||
* @returns {Object} Converted entity object. | ||
*/ | ||
static toEntity({ id, name }) { | ||
return { id, name }; | ||
} | ||
|
||
/** | ||
* Converts the given entity object to a database object. | ||
* | ||
* @param {Object} entityObject Object to convert. | ||
* @returns {Object} Converted database object. | ||
*/ | ||
static toDatabase(entityObject) { | ||
return entityObject; | ||
} | ||
} | ||
|
||
module.exports = SubsystemAdapter; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/** | ||
* @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 { SubsystemAdapter } = require('../adapters'); | ||
const { | ||
models: { | ||
Subsystem, | ||
}, | ||
} = require('../'); | ||
|
||
/** | ||
* Sequelize implementation of the SubsystemRepository. | ||
*/ | ||
class SubsystemRepository { | ||
/** | ||
* Returns all entities. | ||
* | ||
* @param {QueryBuilder} queryBuilder The QueryBuilder to use. | ||
* @returns {Promise} Promise object representing the full mock data | ||
*/ | ||
async findAll(queryBuilder) { | ||
return Subsystem.findAll(queryBuilder.toImplementation()).map(SubsystemAdapter.toEntity); | ||
} | ||
|
||
/** | ||
* Returns all entities. | ||
* | ||
* @param {QueryBuilder} queryBuilder The QueryBuilder to use. | ||
* @returns {Promise} Promise object representing the full mock data | ||
*/ | ||
async findAndCountAll(queryBuilder) { | ||
queryBuilder.set('distinct', true); | ||
|
||
const { count, rows } = await Subsystem.findAndCountAll(queryBuilder.toImplementation()); | ||
return { | ||
count, | ||
subsystems: rows.map(SubsystemAdapter.toEntity), | ||
}; | ||
} | ||
|
||
/** | ||
* Returns a specific entity. | ||
* | ||
* @param {QueryBuilder} queryBuilder The QueryBuilder to use. | ||
* @returns {Promise|Null} Promise object representing the full mock data | ||
*/ | ||
async findOne(queryBuilder) { | ||
queryBuilder.limit(1); | ||
const result = await Subsystem.findOne(queryBuilder.toImplementation()); | ||
return result ? SubsystemAdapter.toEntity(result) : null; | ||
} | ||
|
||
/** | ||
* Inserts a specific entity. | ||
* | ||
* @param {Object} entity The entity to insert. | ||
* @returns {Promise|Null} Promise object representing the full mock data | ||
*/ | ||
async insert(entity){ | ||
const result = await Subsystem.create(SubsystemAdapter.toDatabase(entity)); | ||
return SubsystemAdapter.toEntity(result); | ||
} | ||
|
||
/** | ||
* Removes a specific entity. | ||
* | ||
* @param {QueryBuilder} queryBuilder The QueryBuilder to use. | ||
* @returns {Promise|Null} Promise object representing the full mock data | ||
*/ | ||
async removeOne(queryBuilder) { | ||
queryBuilder.limit(1); | ||
|
||
const tag = await this.findOne(queryBuilder); | ||
if (tag) { | ||
await Subsystem.destroy(queryBuilder.toImplementation()); | ||
} | ||
|
||
return tag; | ||
} | ||
} | ||
|
||
module.exports = new SubsystemRepository(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/** | ||
* @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. | ||
*/ | ||
|
||
module.exports = { | ||
up: (queryInterface, _Sequelize) => queryInterface.bulkInsert('subsystems', [ | ||
{ | ||
name: 'Subsystem Plant #1', | ||
}, | ||
{ | ||
name: 'Subsystem Plant #2', | ||
}, | ||
{ | ||
name: 'Subsystem Plant #3', | ||
}, | ||
]), | ||
|
||
down: (queryInterface, _Sequelize) => queryInterface.bulkDelete('subsystems', null, {}), | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/** | ||
* @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 Joi = require('@hapi/joi'); | ||
const PaginationDto = require('./PaginationDto'); | ||
|
||
const QueryDto = Joi.object({ | ||
page: PaginationDto, | ||
token: Joi.string(), | ||
}); | ||
|
||
const GetAllSubsystemsDto = Joi.object({ | ||
body: Joi.object({}), | ||
params: Joi.object({}), | ||
query: QueryDto, | ||
}); | ||
|
||
module.exports = GetAllSubsystemsDto; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/** | ||
* @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 { | ||
repositories: { | ||
SubsystemRepository, | ||
}, | ||
utilities: { | ||
QueryBuilder, | ||
TransactionHelper, | ||
}, | ||
} = require('../../database'); | ||
|
||
/** | ||
* GetAllSubsystemsUseCase | ||
*/ | ||
class GetAllSubsystemsUseCase { | ||
/** | ||
* Executes this use case. | ||
* | ||
* @param {Object} dto The GetAllSubsystems DTO which contains all request data. | ||
* @returns {Promise} Promise object represents the result of this use case. | ||
*/ | ||
async execute(dto = {}) { | ||
const queryBuilder = new QueryBuilder(); | ||
const { query = {} } = dto; | ||
const { page = {} } = query; | ||
|
||
const { limit = 100, offset = 0 } = page; | ||
queryBuilder.limit(limit); | ||
queryBuilder.offset(offset); | ||
|
||
return TransactionHelper.provide(() => SubsystemRepository.findAndCountAll(queryBuilder)); | ||
} | ||
} | ||
|
||
module.exports = GetAllSubsystemsUseCase; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/** | ||
* @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 GetAllSubsystemsUseCase = require('./GetAllSubsystemsUseCase'); | ||
|
||
module.exports = { | ||
GetAllSubsystemsUseCase, | ||
}; |
Oops, something went wrong.