-
Notifications
You must be signed in to change notification settings - Fork 31
Happy thoughts by Sofie and Oskar #13
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
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider grouping endpoints with similar content, thoughts with thoughts-related and users with user-related.
| } | ||
|
|
||
| // Add this log: | ||
| console.log( |
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.
Consider removing all console.logs.
| message: 'Username and password are required', | ||
| }); | ||
| } | ||
|
|
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.
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.
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 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good work with relevant comments!
https://js-project-happy-thoughts-backend-1.onrender.com/endpoints
https://smilezone78.netlify.app/
Project by Sofie & Oskar