-
-
Notifications
You must be signed in to change notification settings - Fork 76
NW6 | Sabella Fisseha | Server Module | Mailing list #174
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| const express = require("express"); | ||
| const data = require("./mailing-lists"); | ||
| const app = express(); | ||
| app.use(express.json()); | ||
| const lists = new Map(Object.entries(data)); | ||
| app.get("/lists", (req, res) => { | ||
| const listsArray = Array.from(lists.keys()); | ||
| if (listsArray.length > 0) { | ||
| res.status(200).send(listsArray); | ||
| } else { | ||
| res.status(200).send({}); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not correct I'm afraid - the readme asked for an empty array not an empty object |
||
| } | ||
| }); | ||
| app.get("/lists/:name", (req, res) => { | ||
| const name = req.params.name.toLowerCase(); | ||
| const listsArray = lists.get(name); | ||
| if (listsArray) { | ||
| res.status(200).send(listsArray); | ||
| } else { | ||
| res.status(404).send("list not found"); | ||
| } | ||
| }); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
| app.delete("/lists/:name", (req, res) => { | ||
| const name = req.params.name.toLowerCase(); | ||
| if (lists.has(name)) { | ||
| lists.delete(name); | ||
| const updatedList = Array.from(lists.keys()); | ||
| res.status(200).send(updatedList); | ||
| } else { | ||
| res.status(404).send("list not found"); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good work - apprecate the good error checking you have here :) |
||
| } | ||
| }); | ||
| app.put("/lists/:name", (req, res) => { | ||
| const name = req.params.name.toLowerCase(); | ||
| if (lists.has(name)) { | ||
| const putListBody = req.body; | ||
| lists.set(name, putListBody); | ||
| const updatedList = Array.from(lists.keys()); | ||
| res.status(200).send(updatedList); | ||
| } else { | ||
| const putListBody = req.body; | ||
| console.log(putListBody); | ||
| lists.set(name, putListBody); | ||
| const updatedList = Array.from(lists.keys()); | ||
| res.status(201).send(updatedList); | ||
| } | ||
| }); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good work :) |
||
| app.listen(3000, () => { | ||
| console.log("Server is listen to 3000"); | ||
| }); | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any particluar reason you wanted to copy the data into a diffrent object?