Happy thoughts by Sofie and Oskar#13
Happy thoughts by Sofie and Oskar#13ssofiejohansson wants to merge 16 commits intoTechnigo:masterfrom
Conversation
connect to postman with get/post
Connect to frontend
Update backend 12/6
Endpoint showing
Update endpoints get /
/endpoints
const port = process.env.PORT || 8081;
|
Great work Sofie and Oskar always a cute touche to it. |
|
@solen80a Thank you Sofia, but cant seem to see the comments you left? |
| @@ -0,0 +1,33 @@ | |||
| const mongoose = require('mongoose'); | |||
There was a problem hiding this comment.
Seems like this is a duplicate of the Schema in server.js. I suggest you use this Schema instead thou it has more properties for e.g. message, and import it into server.js.
| const port = process.env.PORT || 8081; | ||
| const app = express(); | ||
|
|
||
| const happythoughtsData = JSON.parse(fs.readFileSync('./data.json', 'utf-8')); |
There was a problem hiding this comment.
The connection to the json-file can be removed, all data is fetch from the database.
| mongoose.Promise = Promise; | ||
|
|
||
| // RESET_DB logic | ||
| if (process.env.RESET_DB) { |
There was a problem hiding this comment.
Same as with the file, can be removed, all data is fetch from database.
| } | ||
| }); | ||
|
|
||
| app.get('/users', async (req, res) => { |
There was a problem hiding this comment.
Consider grouping endpoints with similar content, thoughts with thoughts-related and users with user-related.
| } | ||
|
|
||
| // Add this log: | ||
| console.log( |
| message: 'Username and password are required', | ||
| }); | ||
| } | ||
|
|
There was a problem hiding this comment.
Like the approach that you clearly address the user if the username is already taken, nice!
JennieDalgren
left a comment
There was a problem hiding this comment.
Great job with this project! I love the cute little hint in the beginning and you have also met all requirements.
If you were to work more with this I would suggest to start breaking up the server.js file into smaller files. Just as you have done with the model.
Also, commit messages could be improved ;)
Keep up the good work and I look forward to see your final projects.
| // //return all thoughts sorted by likes (most likes on top)(has to be placed before the id route) | ||
| // app.get('/thoughts/likes', async (req, res) => { | ||
| // try { | ||
| // const sortedThoughts = await HappyThoughts.find().sort({ hearts: -1 }); | ||
| // if (sortedThoughts.length > 0) { | ||
| // res.json(sortedThoughts); | ||
| // } else { | ||
| // res.status(404).json({ error: 'No thoughts' }); | ||
| // } | ||
| // } catch (error) { | ||
| // res.status(400).json({ error: 'Invalid request' }); | ||
| // } | ||
| // }); |
There was a problem hiding this comment.
If you dont use this, you could remove it. If you want to keep it to remember or fix later you can add that as a comment
| return res.status(404).json({ error: 'Thought not found' }); | ||
| } | ||
|
|
||
| // Only allow the owner to edit |
There was a problem hiding this comment.
good work with relevant comments!
https://js-project-happy-thoughts-backend-1.onrender.com/endpoints
https://smilezone78.netlify.app/
Project by Sofie & Oskar