-
Notifications
You must be signed in to change notification settings - Fork 8
6 widget routes (fixes issue #6) (Replaces Widget Routes #33) #34
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
jrobcodes
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.
@pllearns comments inline
database/DashboardSchema.js
Outdated
| const WidgetSchema = require('./WidgetSchema') | ||
|
|
||
| const DashboardSchema = mongoose.Schema ({ | ||
| _user: {type: Number, ref: 'User'}, |
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.
Shouldn't this be an ObjectID? Or is this some functionality provided by mongoose? Why is the name _user instead of user?
database/DashboardSchema.js
Outdated
| @@ -0,0 +1,12 @@ | |||
| const mongoose = require('mongoose') | |||
| const Schema = mongoose.Schema | |||
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.
const { Schema } = mongoose
database/User.js
Outdated
| @@ -0,0 +1,16 @@ | |||
| const mongoose = require('mongoose') | |||
| mongoose.connect('mongodb://localhost/lizardboard') | |||
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.
Why do we connect here, but not in the other model file?
database/User.js
Outdated
| const db= mongoose.connection | ||
|
|
||
| const UserSchema = require('./UserSchema') | ||
| db.on('error', console.error.bind(console,'connection error:')) |
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.
We need to separate the setup of the database connection from the definition of the models...
database/UserSchema.js
Outdated
|
|
||
| const UserSchema = mongoose.Schema ({ | ||
| username: String, | ||
| dashboards: [{type: Schema.Types.ObjectId, ref:'Dashboard'}] |
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.
dashboards are not a property of user - the relationship should be stored in the Dashboard object, unless this provides us with some needed functionality?
routes/users.js
Outdated
| }) | ||
| }) | ||
|
|
||
| router.get('/widgets/:widgetId', ( request, response, next ) => { |
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.
Please name the variable :id instead of :widgetId - given the name of the route, it is understood that this is a widget id. Also, why is this route declared in the user routes file? It should be in its own module for widgets route.
routes/users.js
Outdated
| .then( data => console.log('finished') ) | ||
| }) | ||
|
|
||
| router.post('/:userId/widgets', (request, response, next ) => { |
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.
Widgets do not belong to a user, so it does not seem to make sense to include them here. I could see an argument being made for /dashboards/:id/widgets, but we would probably just return the widgets along with the dashboard - it wouldn't make sense to have a set of widgets outside of a dashboard. I think this route will also be removed when we clean up the User model, as requested above (widgets do not belong to users).
routes/users.js
Outdated
| router.post('/:userId/widgets', (request, response, next ) => { | ||
| const { userId } = request.params | ||
| const widget = { type, title, size, contents } | ||
| widget = request.body |
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.
This is not a legal statement - you can not reassign a constant.
routes/users.js
Outdated
| ) | ||
| }) | ||
|
|
||
| router.put('/:userId/widgets/:widgetId', ( request, response, next ) => { |
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.
Omit route; it does not make sense in the context of our domain (users do not contain widgets).
routes/users.js
Outdated
| ) | ||
| }) | ||
|
|
||
| router.delete( '/:userId/widgets/:widgetId', ( request, response, next ) => { |
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; remove route.
jrobcodes
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.
@pllearns @jessehall3 @harmanlearns Comments inline
.gitignore
Outdated
| *.log | ||
| .env | ||
| /build | ||
| ./userRouteNotes.js |
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.
How will the other team get this if it's in gitignore? May as well remove, and remove the file, and send the file to them using conventional means, instead of polluting the gitignore file.
bin/www
Outdated
|
|
||
| mongoose.connect(connection) | ||
| .then(() => console.log('connection successful')) | ||
| .catch((error) => console.error(error)) |
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 we fail to connect, we should probably not start the server...
database/DashboardSchema.js
Outdated
| @@ -0,0 +1,12 @@ | |||
| const mongoose = require('mongoose') | |||
| const { Schema } = mongoose | |||
| const WidgetSchema = require('./WidgetSchema') | |||
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.
WidgetSchema is not used in this file?
database/UserSchema.js
Outdated
| @@ -0,0 +1,10 @@ | |||
| const mongoose = require('mongoose') | |||
| const Schema = mongoose.Schema | |||
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.
Update as in other files.
package.json
Outdated
| "ejs": "^2.5.2", | ||
| "express": "~4.13.4", | ||
| "mongoose": "^4.6.5", | ||
| "mongodb": "^2.2.11", |
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.
Are we using this import, and if so, for what? (since we have mongoose...)
routes/userRouteNotes.js
Outdated
| }) | ||
|
|
||
| router.post('/dashboards/:id/widgets', (request, response, next ) => { | ||
| Widget.create(request.body, (error, post) => { |
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.
Please consider a different name for the post parameter - this is not an intention revealing name
routes/userRouteNotes.js
Outdated
| }) | ||
| }) | ||
|
|
||
| router.put('/:userId/widgets/:widgetId', ( request, response, next ) => { |
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.
Remove this route, widgets do not belong to users.
routes/userRouteNotes.js
Outdated
| ) | ||
| }) | ||
|
|
||
| router.delete( '/:userId/widgets/:widgetId', ( request, response, next ) => { |
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.
Remove this route, widgets do not belong to users.
routes/users.js
Outdated
| const User = require('../database/UserSchema.js') | ||
| const router = express.Router() | ||
| const mongoose = require('mongoose') | ||
| const Widget = require('../database/WidgetSchema.js') |
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.
This import is not used. Also, the filename WidgetSchema is very misleading if this module exports a model - I would move model definition modules into a models folder, instead of database, and remove the Schema part of the file name. As well, files should be named with lower snake case.
routes/users.js
Outdated
| }); | ||
| router.post('/', ( request, response, next ) => { | ||
| User.create(request.body, (error, post) => { | ||
| if ( error ) return next ( error ) |
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.
See above - multi line if, change variable name, formatting issues.
jrobcodes
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.
@pllearns Mostly formatting changes; a few functional and naming changes
bin/www
Outdated
| mongoose.Promise = global.Promise | ||
| const connection = 'mongodb://localhost/lizardboard' | ||
|
|
||
| mongoose.connect(connection) |
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.
This needs to be moved such that it happens prior to server startup. Please move imports to the top of the module, with other imports. We will also need the connection string to be added in a .env file, with instructions added to README on how to set this up.
server.on('error', onError);
server.on('listening', onListening);
mongoose.connect( process.env. MONGODB_URI )
.then( () => server.listen( port ) )
server.listen(port);
routes/users.js
Outdated
| const express = require('express'); | ||
| const router = express.Router(); | ||
| const express = require('express') | ||
| const User = require('../models/user.js') |
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.
Let's not change the order of existing imports - it introduces changes in the diff that aren't really changes. :) Just shift the User import down below the instantiation of router and it should be good
routes/users.js
Outdated
| router.get('/', (request, response, next) => { | ||
| response.send('respond with a resource'); | ||
| }); | ||
| router.post('/', ( request, response, next ) => { |
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.
Add space between ( and '/'
routes/users.js
Outdated
| response.send('respond with a resource'); | ||
| }); | ||
| router.post('/', ( request, response, next ) => { | ||
| User.create(request.body, (error, post) => { |
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.
Add space between ( and request.body, as well as between (, ) and parameters in callback function. Please consider a different name for the parameter post - this does not reveal the intent of this parameter (I'm not sure what it does, is intended to represent, or what data it should hold)
routes/users.js
Outdated
| router.post('/', ( request, response, next ) => { | ||
| User.create(request.body, (error, post) => { | ||
| if ( error ) { | ||
| return next ( error ) |
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.
Indentation off.
routes/users.js
Outdated
| if ( error ) { | ||
| return next ( error ) | ||
| } | ||
| response.json( post ) |
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.
Add whitespace above this line
| div.footer-nav | ||
|
|
||
| include footer | ||
| script(src="/javascripts/index.js") |
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.
Was this change intentional? Wanted to verify since I'm not sure why we're removing sripts from the layout when working on the API.
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.
This was intentional since it isn't needed. Harman pointed this out to me as we were refactoring yesterday.
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.
It causes 304 errors because these files do not exist.
jrobcodes
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.
@pllearns still a few changes needed
| @@ -12,7 +12,10 @@ A mongodb database named lizardboard must be created prior to starting the appli | |||
| - brew install yarn | |||
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.
Please revert changes in this file - these are recommendations, not instructions for setting up the application. See the floworky README for guidance adding instructions for setting up .env
bin/www
Outdated
|
|
||
| mongoose.connect( process.env. MONGODB_URI ) | ||
| .then( () => server.listen( port ) ) | ||
| server.listen( 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.
Remove this line - no need to start the server twice. I think the server.on lines also need to be above this to make sure set up occurs properly
routes/users.js
Outdated
| User.create( request.body, ( error, user ) => { | ||
|
|
||
| module.exports = router; | ||
| if ( error ) { |
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.
Indentation is still messed up in this router. Please correct.
jrobcodes
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.
@pllearns Moar changes
README.md
Outdated
| ``` echo MONGODB_URI=mongodb://`whoami`@localhost:3000/lizardboard >> .env | ||
| ``` | ||
|
|
||
| ## (Optional) Configuration for test RESTful APIs |
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.
Configuration for test_ing_
README.md
Outdated
| - yarn start (start the server) | ||
|
|
||
| Lizardboard needs an .env file to specify environment variables that are required to run the application. | ||
| ``` echo MONGODB_URI=mongodb://`whoami`@localhost:3000/lizardboard >> .env |
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.
Shouldn't this just be mongodb://localhost/lizardboard?
bin/www
Outdated
| app.set('port', port); | ||
|
|
||
| mongoose.connect( connection ) | ||
| .then( () => server.listen( 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.
Indentation off
routes/users.js
Outdated
| response.send('respond with a resource'); | ||
| }); | ||
| router.post( '/', ( request, response, next ) => { | ||
| User.create( request.body, ( error, user ) => { |
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.
Missed this in previous commits; sorry `bout that - these should be promisified. See harman and jesse, they've got an example in their PR
-Updated RESTful APIs
-Updated naming conventions for schemas
-Refactored code and cleaned out comments