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

Add new feature Stack #163

Open
wants to merge 5 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules
.env
31 changes: 31 additions & 0 deletions README
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Hola esta es mi solucion

- Primero creo un metodo llamado "filterByStack"
- Segundo este metodo recibe 2 parametros los cuales son: "explorers" y "stack"
- El siguiente punto es que trabajaremos a base del filtrado, es decir filtraremos los explorers que
cumplan con las condiciones.
- Luego usaremos el arreglo de stacks veremos si el stack que buscamos, existe en este arreglo

<img title="a title" alt="Alt text" width='600px' src="./imgReadme/methodFilterByStack.png">

Luego en la clase "ExplorerController.js" agregamos la nueva funcion para pasarla a la ruta:

<img title="a title" alt="Alt text" width='600px' src="./imgReadme/methodFilterByStackController.png">

Aqui si nos damos cuenta solo pasamos el stack, pasamos el parametro de la ruta que deseamos filtrar

Luego en nuestro controlador va a quedar con la nueva ruta:

<img title="a title" alt="Alt text" width='600px' src="./imgReadme/appController.png">

## Resultado final

Pruebas:

Este sera el resultado con javascript

<img title="a title" alt="Alt text" width='600px' src="./imgReadme/Resultados.png">

Este sera el resultado con Elm

<img title="a title" alt="Alt text" width='600px' src="./imgReadme/ResultadoElm.png">
Binary file added imgReadme/ResultadoElm.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added imgReadme/Resultados.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added imgReadme/appController.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added imgReadme/methodFilterByStack.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added imgReadme/methodFilterByStackController.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
47 changes: 47 additions & 0 deletions lib/bot.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
require("dotenv").config();
const TelegramBot = require("node-telegram-bot-api");
const ExplorerController = require("./controllers/ExplorerController");

// replace the value below with the Telegram token you receive from @BotFather
const token = process.env.KEY;

// Create a bot that uses 'polling' to fetch new updates
const bot = new TelegramBot(token, { polling: true });

// Matches "/echo [whatever]"
bot.onText(/\/echo (.+)/, (msg, match) => {
// 'msg' is the received Message from Telegram
// 'match' is the result of executing the regexp above on the text content
// of the message

const chatId = msg.chat.id;
const resp = match[1]; // the captured "whatever"

// send back the matched "whatever" to the chat
bot.sendMessage(chatId, resp);
});

// Listen for any kind of message. There are different kinds of
// messages.
bot.on("message", msg => {
const chatId = msg.chat.id;
const numberToApplyFb = parseInt(msg.text);

const messageText = msg.text;

console.log(msg);

console.log(msg.text);

if (!isNaN(numberToApplyFb)) {
const fizzbuzzTrick = ExplorerController.applyFizzbuzz(numberToApplyFb);
const responseBot = `Tu número es: ${numberToApplyFb}. Validación: ${fizzbuzzTrick}`;
bot.sendMessage(chatId, responseBot);
} else {
bot.sendMessage(chatId, "Envía un número válido ");
}
if (messageText === "node" || messageText === "java") {
const mission = ExplorerController.getExplorersByMission(messageText);
bot.sendMessage(chatId, JSON.stringify(mission));
}
});
14 changes: 9 additions & 5 deletions lib/controllers/ExplorerController.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,29 @@ const ExplorerService = require("../services/ExplorerService");
const FizzbuzzService = require("../services/FizzbuzzService");
const Reader = require("../utils/reader");

class ExplorerController{
static getExplorersByMission(mission){
class ExplorerController {
static getExplorersByMission(mission) {
const explorers = Reader.readJsonFile("explorers.json");
return ExplorerService.filterByMission(explorers, mission);
}

static applyFizzbuzz(score){
static applyFizzbuzz(score) {
return FizzbuzzService.applyValidationInNumber(score);
}

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

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

module.exports = ExplorerController;
44 changes: 29 additions & 15 deletions lib/server.js
Original file line number Diff line number Diff line change
@@ -1,38 +1,52 @@
const ExplorerController = require("./controllers/ExplorerController");
const express = require("express");

const app = express();
app.use(express.json());
const port = 3000;

app.get("/", (request, response) => {
response.json({message: "FizzBuzz Api welcome!"});
response.json({ message: "FizzBuzz Api welcome!" });
});

app.get("/v1/explorers/:mission", (request, response) => {
const mission = request.params.mission;
const explorersInMission = ExplorerController.getExplorersByMission(mission);
response.json(explorersInMission);
const mission = request.params.mission;
const explorersInMission = ExplorerController.getExplorersByMission(mission);
response.json(explorersInMission);
});

app.get("/v1/explorers/amount/:mission", (request, response) => {
const mission = request.params.mission;
const explorersAmountInMission = ExplorerController.getExplorersAmonutByMission(mission);
response.json({mission: request.params.mission, quantity: explorersAmountInMission});
const mission = request.params.mission;
const explorersAmountInMission =
ExplorerController.getExplorersAmonutByMission(mission);
response.json({
mision: request.params.mission,
quantity: explorersAmountInMission,
});
});

app.get("/v1/explorers/usernames/:mission", (request, response) => {
const mission = request.params.mission;
const explorersUsernames = ExplorerController.getExplorersUsernamesByMission(mission);
response.json({mission: request.params.mission, explorers: explorersUsernames});
const mission = request.params.mission;
const explorersUsernames =
ExplorerController.getExplorersUsernamesByMission(mission);
response.json({
mission: request.params.mission,
explorers: explorersUsernames,
});
});

app.get("/v1/fizzbuzz/:score", (request, response) => {
const score = parseInt(request.params.score);
const fizzbuzzTrick = ExplorerController.applyFizzbuzz(score);
response.json({score: score, trick: fizzbuzzTrick});
const score = parseInt(request.params.score);
const fizzbuzzTrick = ExplorerController.applyFizzbuzz(score);
response.json({ score: score, trick: fizzbuzzTrick });
});

app.listen(port, () => {
console.log(`FizzBuzz API in localhost:${port}`);
app.get("/v1/explorers/stack/:stack", (request, response) => {
const { stack } = request.params;
const stacksExplorers = ExplorerController.getExplorersByStack(stack);
response.json(stacksExplorers);
});

app.listen(port, () => {
console.log(`FizzBuzz API in localhost:${port}`);
});
32 changes: 24 additions & 8 deletions lib/services/ExplorerService.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,37 @@
class ExplorerService {

static filterByMission(explorers, mission){
const explorersByMission = explorers.filter((explorer) => explorer.mission == mission);
static filterByMission(explorers, mission) {
const explorersByMission = explorers.filter(
(explorer) => explorer.mission == mission
);
return explorersByMission;
}

static getAmountOfExplorersByMission(explorers, mission){
const explorersByMission = ExplorerService.filterByMission(explorers, mission);
static getAmountOfExplorersByMission(explorers, mission) {
const explorersByMission = ExplorerService.filterByMission(
explorers,
mission
);
return explorersByMission.length;
}

static getExplorersUsernamesByMission(explorers, mission){
const explorersByMission = ExplorerService.filterByMission(explorers, mission);
const explorersUsernames = explorersByMission.map((explorer) => explorer.githubUsername);
static getExplorersUsernamesByMission(explorers, mission) {
const explorersByMission = ExplorerService.filterByMission(
explorers,
mission
);
const explorersUsernames = explorersByMission.map(
(explorer) => explorer.githubUsername
);
return explorersUsernames;
}

static filterByStack(explorers, stack) {
const explorersByStack = explorers.filter(
(explorer) => explorer.stacks.includes(stack) === true
);

return explorersByStack;
}
}

module.exports = ExplorerService;
Loading