Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding 'getExplorersByStack' function, and endpoint #160

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/controllers/ExplorerController.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ class ExplorerController{
const explorers = Reader.readJsonFile("explorers.json");
return ExplorerService.getAmountOfExplorersByMission(explorers, mission);
}

static getExplorersByStack(mission) {
const explorers = Reader.readJsonFile("explorers.json);
return ExplorerService.getExplorersByStack(explorers, mission);
}
}

module.exports = ExplorerController;
5 changes: 5 additions & 0 deletions lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ 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;
response.json(ExplorerController.getExplorersByStack(stack));
});

app.listen(port, () => {
console.log(`FizzBuzz API in localhost:${port}`);
});
Expand Down
7 changes: 6 additions & 1 deletion lib/services/ExplorerService.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ class ExplorerService {
const explorersUsernames = explorersByMission.map((explorer) => explorer.githubUsername);
return explorersUsernames;
}


static getExplorersByStack(explorers, mission) {
return explorers.filter((explorer) => {
return explorer.stacks.includes(mission);
});
}
}

module.exports = ExplorerService;