Conversation
…hts, /thoughts:id
JennieDalgren
left a comment
There was a problem hiding this comment.
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.
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.
great linking here to the other collection
casalm26
left a comment
There was a problem hiding this comment.
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.
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.
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, |
| // 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.
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