Files
bch-dex/src/controllers/rest-api/index.js
T

64 lines
2.0 KiB
JavaScript
Raw Normal View History

2021-07-05 19:36:56 -07:00
/*
This index file for the Clean Architecture Controllers loads dependencies,
creates instances, and attaches the controller to REST API endpoints for
Koa.
*/
// Public npm libraries.
2022-09-08 08:58:39 -07:00
// Local libraries
import AuthRESTController from './auth/index.js'
import UserRouter from './users/index.js'
import ContactRESTController from './contact/index.js'
import LogsRESTController from './logs/index.js'
2023-10-23 20:28:17 -07:00
import IpfsRESTController from './ipfs/index.js'
2021-07-05 19:36:56 -07:00
2021-07-06 19:29:49 -07:00
class RESTControllers {
constructor (localConfig = {}) {
2021-07-06 19:29:49 -07:00
// Dependency Injection.
this.adapters = localConfig.adapters
if (!this.adapters) {
throw new Error(
'Instance of Adapters library required when instantiating REST Controller libraries.'
2021-07-06 19:29:49 -07:00
)
}
this.useCases = localConfig.useCases
if (!this.useCases) {
throw new Error(
'Instance of Use Cases library required when instantiating REST Controller libraries.'
2021-07-06 19:29:49 -07:00
)
}
2021-07-10 09:04:03 -07:00
// console.log('Controllers localConfig: ', localConfig)
2021-07-06 19:29:49 -07:00
}
attachRESTControllers (app) {
const dependencies = {
adapters: this.adapters,
useCases: this.useCases
}
// Attach the REST API Controllers associated with the /auth route
const authRESTController = new AuthRESTController(dependencies)
authRESTController.attach(app)
// Attach the REST API Controllers associated with the /user route
const userRouter = new UserRouter(dependencies)
userRouter.attach(app)
2021-07-06 19:29:49 -07:00
// Attach the REST API Controllers associated with the /contact route
const contactRESTController = new ContactRESTController(dependencies)
contactRESTController.attach(app)
// Attach the REST API Controllers associated with the /logs route
const logsRESTController = new LogsRESTController(dependencies)
logsRESTController.attach(app)
2023-10-23 20:28:17 -07:00
// Attach the REST API Controllers associated with the /ipfs route
const ipfsRESTController = new IpfsRESTController(dependencies)
ipfsRESTController.attach(app)
2021-07-06 19:29:49 -07:00
}
2021-07-05 19:36:56 -07:00
}
2022-09-08 08:58:39 -07:00
export default RESTControllers