-
Notifications
You must be signed in to change notification settings - Fork 31
Happy Thoughts API - Linda L #22
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: master
Are you sure you want to change the base?
Conversation
…hts, /thoughts:id
JennieDalgren
left a comment
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.
Great job with this project.
I'm missing a documentation of your API. Without reading all your code it is tricky to know what endpoints there is and methods. It is one of the requirements for the project.
Documentation of your API using e.g. Express List Endpoints
Also, I can't find the backend reflected in our frontend? Or did you create a new frontend to this project? I tried this one: https://happythoughtproject.netlify.app/
Take a look and ping me when it's done.
💪 🌷
middlewares/authenticateUser.js
Outdated
| req.user = user; // Lägg till användaren på request-objektet | ||
| next(); // Gå vidare till nästa steg (ex. route handler) |
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.
stick to english comments, easier for the reviewer to understand
| type: mongoose.Schema.Types.ObjectId, | ||
| ref: "User", | ||
| required: true, |
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.
great linking here to the other collection
casalm26
left a comment
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.
Hi Linda!
Very well done. The code is neat and easy to navigate. i've just made a couple of suggestions of improvements that could be made in the future to make the API even more reliable. Not much else to comment on, great job!
| // get single post | ||
| router.get("/:id", async (req, res) => { | ||
| try { | ||
| const thought = await HappyThought.findById(req.params.id); | ||
| if (thought) { | ||
| res.json(thought); | ||
| } else { | ||
| res.status(404).json({ error: "Thought not found" }); | ||
| } | ||
| } catch (error) { | ||
| res.status(400).json({ error: "Invalid ID format" }); | ||
| } | ||
| }); |
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 this used in the frontend?? It's a neat solution, just asking what the use of getting a single thought is here!
| } | ||
| }); | ||
|
|
||
| export default router; |
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.
For future developments - maybe consider adding some rate limits on creation of posts? That way, a user can't flood the feed. :)
| password: { | ||
| type: String, | ||
| required: true, | ||
| minlength: 5, |
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.
Maybe add a maxLength here as well?
| // add new post | ||
| router.post("/", authenticateUser, async (req, res) => { | ||
| const { message } = req.body; | ||
|
|
||
| try { | ||
| const newThought = new HappyThought({ | ||
| message, | ||
| createdBy: req.user._id, // lägg till användaren som skapar | ||
| }); | ||
|
|
||
| const savedThought = await newThought.save(); | ||
| res.status(201).json(savedThought); | ||
| } catch (error) { | ||
| res.status(400).json({ error: "Invalid input", details: error.errors }); | ||
| } | ||
| }); |
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.
Possibly add input validation here as well?
|
Still can't fint the frontend that is hooked up to this backend? |
|
ping ☝️ |
|
ping |
Please include your Render link: https://happy-thoughts-api-784k.onrender.com