-
-
Notifications
You must be signed in to change notification settings - Fork 76
NW6 | Rabia Avci | Module Servers | [TECH ED] Mailing list API Project | Week 4 #177
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
63eeb42
c6a5e26
77a9122
991e480
b890924
034bca1
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 |
|---|---|---|
| @@ -1,8 +1,5 @@ | ||
| module.exports = { | ||
| export default { | ||
| staff: ["talea@techtonica.org", "michelle@techtonica.org"], | ||
| "cohort-h1-2020": [ | ||
| "ali@techtonica.org", | ||
| "humail@techtonica.org", | ||
| "khadar@techtonica.org", | ||
| ], | ||
| "cohort-h1-2020": ["ali@techtonica.org", "humail@techtonica.org", "khadar@techtonica.org"], | ||
| }; | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| import express from "express"; | ||
| import mailinglist from "./mailing-lists.js"; | ||
| const PORT = 3000; | ||
|
|
||
| const app = express(); | ||
| app.use(express.json()); | ||
| app.disable("x-powered-by"); | ||
|
|
||
| const mailList = mailinglist; | ||
|
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. Another line that doesn't make too much sense to me - is there any particuluar reason that the var needs reassigned? |
||
|
|
||
| // fetch all list names | ||
| app.get("/lists", (req, res) => { | ||
| const listsArray = Object.keys(mailList); | ||
| res.status(200).json(listsArray); | ||
| }); | ||
|
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, appreciate the comments - makes it easier to skim read |
||
|
|
||
| // get a single name | ||
| app.get("/lists/:name", (req, res) => { | ||
| const name = req.params.name; | ||
| const list = mailList[name]; | ||
| if (list) { | ||
| res.status(200).json({ name, members: list }); | ||
| } else { | ||
| res.status(404).json({ error: "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. 👍 |
||
|
|
||
| // delete a name | ||
| app.delete("/lists/:name", (req, res) => { | ||
| const name = req.params.name; | ||
| if (mailList[name]) { | ||
| delete mailList[name]; | ||
| res.status(200).json({ message: "Successfully deleted" }); | ||
| } else { | ||
| res.status(404).json({ message: "Name not found for delete" }); | ||
| } | ||
| }); | ||
|
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. 👍 |
||
|
|
||
| // add or update a list | ||
| app.put("/lists/:name", (req, res) => { | ||
| const pathName = req.params.name; | ||
| const { name, members } = req.body; | ||
|
|
||
| if (pathName !== name) { | ||
| res.status(400).json({ error: "Name in path does not match name in body" }); | ||
| return; | ||
| } | ||
|
|
||
| if (mailList[name]) { | ||
| mailList[name] = members; | ||
| res.status(200).json({ message: "List updated successfully." }); | ||
| } else { | ||
| mailList[name] = members; | ||
| res.status(201).json({ message: "New list created successfully." }); | ||
| } | ||
| }); | ||
|
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. Amazing, nice to see you've done the stretch goal as well! |
||
|
|
||
| app.listen(PORT, () => { | ||
| console.log(`Server is running on port ${PORT}`); | ||
| }); | ||
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 particulaur reason for this line of code? It's a good question to ask yourself whenever you find anything odd in code.