diff --git a/.gitignore b/.gitignore index 3c3629e6..9f7b1e68 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -node_modules +**node_modules +**package.json \ No newline at end of file diff --git a/lib/controllers/ExplorerController.js b/lib/controllers/ExplorerController.js index 85590a6d..260abba3 100644 --- a/lib/controllers/ExplorerController.js +++ b/lib/controllers/ExplorerController.js @@ -21,6 +21,10 @@ class ExplorerController{ const explorers = Reader.readJsonFile("explorers.json"); return ExplorerService.getAmountOfExplorersByMission(explorers, mission); } + static getExplorersByStack(stack){ + const explorers = Reader.readJsonFile("explorers.json"); + return ExplorerService.getExplorersByStack(explorers, stack); + } } module.exports = ExplorerController; diff --git a/lib/server.js b/lib/server.js index 9860b437..bc0caf5e 100644 --- a/lib/server.js +++ b/lib/server.js @@ -31,7 +31,11 @@ app.get("/v1/fizzbuzz/:score", (request, response) => { const fizzbuzzTrick = ExplorerController.applyFizzbuzz(score); response.json({score: score, trick: fizzbuzzTrick}); }); - +app.get("/v1/explorers/stack/:stack", (request, response)=>{ + const stack = request.params.stack; + const filtered = ExplorerController.getExplorersByStack(stack); + response.json(filtered); +}); app.listen(port, () => { console.log(`FizzBuzz API in localhost:${port}`); }); diff --git a/lib/services/ExplorerService.js b/lib/services/ExplorerService.js index 9fef9574..68e2a2b6 100644 --- a/lib/services/ExplorerService.js +++ b/lib/services/ExplorerService.js @@ -15,7 +15,14 @@ class ExplorerService { const explorersUsernames = explorersByMission.map((explorer) => explorer.githubUsername); return explorersUsernames; } - + static getExplorersByStack(explorers, stack){ + const explorersWithStack = explorers.filter((explorer) => { + if(explorer.stacks.includes(stack)) + return explorer; + }); + return explorersWithStack; + } } + module.exports = ExplorerService; diff --git a/package-lock.json b/package-lock.json index bb4f2aae..06321e48 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,8 @@ "version": "1.0.0", "license": "ISC", "dependencies": { - "express": "^4.17.3" + "express": "^4.17.3", + "lodash": "^4.17.21" }, "devDependencies": { "eslint": "^8.14.0", @@ -3711,8 +3712,7 @@ "node_modules/lodash": { "version": "4.17.21", "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz", - "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==", - "dev": true + "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==" }, "node_modules/lodash.merge": { "version": "4.6.2", @@ -7883,8 +7883,7 @@ "lodash": { "version": "4.17.21", "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz", - "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==", - "dev": true + "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==" }, "lodash.merge": { "version": "4.6.2", diff --git a/test/services/ExplorerService.test.js b/test/services/ExplorerService.test.js index 4313f192..7a6cea5c 100644 --- a/test/services/ExplorerService.test.js +++ b/test/services/ExplorerService.test.js @@ -1,4 +1,6 @@ +const Reader = require("../../lib/utils/reader"); const ExplorerService = require("./../../lib/services/ExplorerService"); +const explorers = Reader.readJsonFile("explorers.json"); describe("Tests para ExplorerService", () => { test("Requerimiento 1: Calcular todos los explorers en una misiĆ³n", () => { @@ -6,5 +8,19 @@ describe("Tests para ExplorerService", () => { const explorersInNode = ExplorerService.filterByMission(explorers, "node"); expect(explorersInNode.length).toBe(1); }); + test("2. Filtrar los explorers por stack", ()=>{ + const explorers = Reader.readJsonFile("explorers.json"); + const filter = ExplorerService.getExplorersByStack(explorers, "javascript"); + const filter1 = ExplorerService.getExplorersByStack(explorers, "elm"); + const filter2 = ExplorerService.getExplorersByStack(explorers, "groovy"); + const filter3 = ExplorerService.getExplorersByStack(explorers, "reasonML"); + const filter4 = ExplorerService.getExplorersByStack(explorers, "elixir"); + + for(let i =0; i