fix(controllers): Made Controllers library a class

This commit is contained in:
Chris Troutner
2021-07-25 16:49:01 -07:00
parent c46f7357c3
commit 44867f0173
3 changed files with 78 additions and 32 deletions
+70 -28
View File
@@ -14,39 +14,81 @@ const JSONRPC = require('./json-rpc')
// Load the Clean Architecture Use Case libraries.
const UseCases = require('../use-cases')
const useCases = new UseCases({ adapters })
// const useCases = new UseCases({ adapters })
// Load the REST API Controllers.
const RESTControllers = require('./rest-api')
class Controllers {
constructor (localConfig = {}) {
this.adapters = adapters
this.useCases = new UseCases({ adapters })
}
async attachControllers (app) {
// Attach the REST controllers to the Koa app.
this.attachRESTControllers(app)
// Start IPFS.
await this.adapters.ipfs.start()
this.attachRPCControllers()
}
// Top-level function for this library.
// Start the various Controllers and attach them to the app.
attachRESTControllers (app) {
const rESTControllers = new RESTControllers({
adapters: this.adapters,
useCases: this.useCases
})
// Attach the REST API Controllers associated with the boilerplate code to the Koa app.
rESTControllers.attachRESTControllers(app)
}
// Add the JSON RPC router to the ipfs-coord adapter.
attachRPCControllers () {
const jsonRpcController = new JSONRPC({
adapters: this.adapters,
useCases: this.useCases
})
// Attach the input of the JSON RPC router to the output of ipfs-coord.
this.adapters.ipfs.ipfsCoordAdapter.attachRPCRouter(
jsonRpcController.router
)
}
}
// Top-level function for this library.
// Start the various Controllers and attach them to the app.
async function attachControllers (app) {
// Attach the REST controllers to the Koa app.
attachRESTControllers(app)
// async function attachControllers (app) {
// // Attach the REST controllers to the Koa app.
// attachRESTControllers(app)
//
// // Start IPFS.
// await adapters.ipfs.start()
//
// attachRPCControllers()
// }
//
// function attachRESTControllers (app) {
// const rESTControllers = new RESTControllers({
// adapters,
// useCases
// })
//
// // Attach the REST API Controllers associated with the boilerplate code to the Koa app.
// rESTControllers.attachRESTControllers(app)
// }
// Start IPFS.
await adapters.ipfs.start()
// // Add the JSON RPC router to the ipfs-coord adapter.
// function attachRPCControllers () {
// const jsonRpcController = new JSONRPC({ adapters, useCases })
//
// // Attach the input of the JSON RPC router to the output of ipfs-coord.
// adapters.ipfs.ipfsCoordAdapter.attachRPCRouter(jsonRpcController.router)
// }
attachRPCControllers()
}
function attachRESTControllers (app) {
const rESTControllers = new RESTControllers({
adapters,
useCases
})
// Attach the REST API Controllers associated with the boilerplate code to the Koa app.
rESTControllers.attachRESTControllers(app)
}
// Add the JSON RPC router to the ipfs-coord adapter.
function attachRPCControllers () {
const jsonRpcController = new JSONRPC({ adapters, useCases })
// Attach the input of the JSON RPC router to the output of ipfs-coord.
adapters.ipfs.ipfsCoordAdapter.attachRPCRouter(jsonRpcController.router)
}
module.exports = { attachControllers }
module.exports = Controllers