From f3e312aa7de8897c94e5e167a58fce8627ab010c Mon Sep 17 00:00:00 2001 From: Juan Morales <99295980+JuanMorales26@users.noreply.github.com> Date: Thu, 12 May 2022 20:36:45 -0500 Subject: [PATCH 1/3] Agregando Enpoint Para Stacks --- lib/server.js | 6 ++++++ 1 file changed, 6 insertions(+) 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}`); }); From 99e42b7e8d51b07c012f4158819d80dd3d63da62 Mon Sep 17 00:00:00 2001 From: Juan Morales <99295980+JuanMorales26@users.noreply.github.com> Date: Thu, 12 May 2022 20:37:54 -0500 Subject: [PATCH 2/3] Agregando funcion para ExplorerController MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Función que solicita a los explorers que tengan en stack el valor ingresado desde la web --- lib/controllers/ExplorerController.js | 7 +++++++ 1 file changed, 7 insertions(+) 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; From b9eeff38d30ec24de62437499d4d3a3f8946a8f5 Mon Sep 17 00:00:00 2001 From: Juan Morales <99295980+JuanMorales26@users.noreply.github.com> Date: Thu, 12 May 2022 20:38:31 -0500 Subject: [PATCH 3/3] Agregando funcion Stack a Service --- lib/services/ExplorerService.js | 5 +++++ 1 file changed, 5 insertions(+) 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; + } }