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

Requerimiento para obtener explorers por stack #152

Open
wants to merge 6 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
10 changes: 2 additions & 8 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,12 @@ module.exports = {
"env": {
"browser": true,
"commonjs": true,
"es2021": true,
"jest": true
"es2021": true
},
"extends": "eslint:recommended",
"parserOptions": {
"ecmaVersion": "latest"
},
"rules": {
"no-unused-vars": "off",
indent: ["error", 4],
"linebreak-style": ["error", "unix"],
quotes: ["error", "double"],
semi: ["error", "always"]
}
};
}
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: Run Tests in my project every push on GitHub

on: [push, pull_request]
on: [push]

jobs:
build:
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules
**/node_modules
**/package.json
9 changes: 9 additions & 0 deletions lib/controllers/ExplorerController.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const ExplorerService = require("../services/ExplorerService");
const FizzbuzzService = require("../services/FizzbuzzService");
const StackService = require("../services/StackService");
const Reader = require("../utils/reader");

class ExplorerController{
Expand All @@ -21,6 +22,14 @@ class ExplorerController{
const explorers = Reader.readJsonFile("explorers.json");
return ExplorerService.getAmountOfExplorersByMission(explorers, mission);
}

static getExplorersByStack(stack){

const explorers = Reader.readJsonFile("explorers.json");
const explorerStack = StackService.getExplorersByStack(explorers,stack);
return explorerStack;
}
}

module.exports = ExplorerController;

10 changes: 10 additions & 0 deletions lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,16 @@ app.get("/v1/fizzbuzz/:score", (request, response) => {
response.json({score: score, trick: fizzbuzzTrick});
});

app.get("/v1/explorers/stack/:stack",(req,res) => {
const stack = req.params.stack;

const ExplorersByStack = ExplorerController.getExplorersByStack(stack);

res.json(ExplorersByStack);


});

app.listen(port, () => {
console.log(`FizzBuzz API in localhost:${port}`);
});
Expand Down
3 changes: 3 additions & 0 deletions lib/services/ExplorerService.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ class ExplorerService {
return explorersUsernames;
}



}

module.exports = ExplorerService;

20 changes: 20 additions & 0 deletions lib/services/StackService.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
class StackService {

static getExplorersByStack(explorers,stack){

const getExplorers = explorers.filter((filter) => filter.stacks.includes(stack));
return getExplorers;
}

static getUsernamesByStack(explorers,stack){

const getExplorers = explorers.filter((filter) => filter.stacks.includes(stack));
const onlyUsernames = getExplorers.map((usernames) => usernames.name);
return onlyUsernames;

}

}


module.exports = StackService;
1 change: 1 addition & 0 deletions lib/utils/reader.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ class Reader{
}

module.exports = Reader;

90 changes: 45 additions & 45 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "",
"main": "index.js",
"scripts": {
"test": "node ./node_modules/.bin/jest",
"test": "node ./node_modules/jest/bin/jest.js",
"linter": "node ./node_modules/eslint/bin/eslint.js",
"linter-fix": "node ./node_modules/eslint/bin/eslint.js . --fix",
"server": "node ./lib/server.js"
Expand All @@ -13,7 +13,7 @@
"author": "",
"license": "ISC",
"devDependencies": {
"eslint": "^8.14.0",
"eslint": "^8.15.0",
"jest": "^27.5.1"
},
"dependencies": {
Expand Down
Loading