From dc6bece6ac897a1660fcb014a82c173715a44c7a Mon Sep 17 00:00:00 2001 From: Mohamed Mantawy Date: Tue, 12 Feb 2019 20:23:14 +0200 Subject: [PATCH] Add files via upload --- server/index.js | 73 +++++++++++++++++++++++++------------------------ 1 file changed, 37 insertions(+), 36 deletions(-) diff --git a/server/index.js b/server/index.js index 92f8d56..50d61c6 100644 --- a/server/index.js +++ b/server/index.js @@ -1,37 +1,38 @@ -const express = require('express'); -const app = express(); - -const students = [ - { id: "28-09121", name: "Omar Sherif", github_username: "osheriff", email: "omarr@whatever.com" }, - { id: "21-094123", name: "Mathew White", github_username: "matheww", email: "matheww@whatever.com" }, - { id: "15-10312", name: "Dom Sundle", github_username: "domss", email: "domss.whatever.com" }, - { id: "7223", name: "Gehad Ismail", github_username: "Gehad93", email: "gehad.ismail@guc.edu.eg" } -]; - -app.get('/', (request, response) => { - response.send(`Students`); -}); - -app.get('/api/students', (request, response) => { - let data = ""; - students.forEach((value) => { - const user_id = value.id; - const user_name = value.name; - data += `${user_name}
`; - }); - response.send(data); -}); - -app.get('/api/students/:id', (request, response) => { - var data = ""; - students.forEach((value) => { - if(value.id === request.params.id) { - data = `Id: ${value.id}
Name: ${value.name}
Email: ${value.email}
Github: ${value.github_username}`; - return; - } - }); - response.send(data || 'No student matches the requested id'); -}); - -const port = 3000; +const express = require('express'); +const app = express(); + +const students = [ + { id: "28-09121", name: "Omar Sherif", github_username: "osheriff", email: "omarr@whatever.com" }, + { id: "21-094123", name: "Mathew White", github_username: "matheww", email: "matheww@whatever.com" }, + { id: "15-10312", name: "Dom Sundle", github_username: "domss", email: "domss.whatever.com" }, + { id: "7223", name: "Gehad Ismail", github_username: "Gehad93", email: "gehad.ismail@guc.edu.eg" }, + { id: "40-19563", name: "Mohamed Mantawy", github_username: "B1aCkManTa", email: "mohamed.mantawy@student.guc.edu.eg" } +]; + +app.get('/', (request, response) => { + response.send(`Students`); +}); + +app.get('/api/students', (request, response) => { + let data = ""; + students.forEach((value) => { + const user_id = value.id; + const user_name = value.name; + data += `${user_name}
`; + }); + response.send(data); +}); + +app.get('/api/students/:id', (request, response) => { + var data = ""; + students.forEach((value) => { + if(value.id === request.params.id) { + data = `Id: ${value.id}
Name: ${value.name}
Email: ${value.email}
Github: ${value.github_username}`; + return; + } + }); + response.send(data || 'No student matches the requested id'); +}); + +const port = 3000; app.listen(port, () => console.log(`Listening on port ${port}`)); \ No newline at end of file