diff --git a/lib/controllers/ExplorerController.js b/lib/controllers/ExplorerController.js index 85590a6d..ae4929f7 100644 --- a/lib/controllers/ExplorerController.js +++ b/lib/controllers/ExplorerController.js @@ -21,6 +21,13 @@ class ExplorerController{ const explorers = Reader.readJsonFile("explorers.json"); return ExplorerService.getAmountOfExplorersByMission(explorers, mission); } + + static explorersbystack(stack){ + const path = "./explorers/explorers.json"; + const explorers = Reader.readJSONFile(path); + const explorersbyStack = ExplorerService.getExplorersByStack(explorers, stack); + return explorersbyStack; + } } module.exports = ExplorerController; diff --git a/lib/server.js b/lib/server.js index 9860b437..3b488059 100644 --- a/lib/server.js +++ b/lib/server.js @@ -32,6 +32,12 @@ app.get("/v1/fizzbuzz/:score", (request, response) => { response.json({score: score, trick: fizzbuzzTrick}); }); +app.get("/v1/explorers/stack/:stack", (request, response) => { + const stack = request.params.stack; + const explorers_with_that_stack = ExplorerController.explorersbystack(stack); + response.json({stack: request.params.stack, explorers: explorers_with_that_stack}); +}); + app.listen(port, () => { console.log(`FizzBuzz API in localhost:${port}`); }); diff --git a/lib/services/ExplorerService.js b/lib/services/ExplorerService.js index 9fef9574..30d0b5d2 100644 --- a/lib/services/ExplorerService.js +++ b/lib/services/ExplorerService.js @@ -15,6 +15,11 @@ class ExplorerService { const explorersUsernames = explorersByMission.map((explorer) => explorer.githubUsername); return explorersUsernames; } + + static getExplorersByStack(explorers, stack){ + const explorersbyStack = explorers.filter((explorer) => explorer.stacks.includes(stack)); + return explorersbyStack; + } }