Skip to content

Conversation

@pllearns
Copy link
Contributor

@pllearns pllearns commented Nov 9, 2016

-Updated RESTful APIs
-Updated naming conventions for schemas
-Refactored code and cleaned out comments

Copy link
Contributor

@jrobcodes jrobcodes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pllearns comments inline

const WidgetSchema = require('./WidgetSchema')

const DashboardSchema = mongoose.Schema ({
_user: {type: Number, ref: 'User'},
Copy link
Contributor

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?

@@ -0,0 +1,12 @@
const mongoose = require('mongoose')
const Schema = mongoose.Schema
Copy link
Contributor

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')
Copy link
Contributor

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:'))
Copy link
Contributor

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...


const UserSchema = mongoose.Schema ({
username: String,
dashboards: [{type: Schema.Types.ObjectId, ref:'Dashboard'}]
Copy link
Contributor

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 ) => {
Copy link
Contributor

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 ) => {
Copy link
Contributor

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
Copy link
Contributor

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 ) => {
Copy link
Contributor

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 ) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same; remove route.

Copy link
Contributor

@jrobcodes jrobcodes left a 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
Copy link
Contributor

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))
Copy link
Contributor

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...

@@ -0,0 +1,12 @@
const mongoose = require('mongoose')
const { Schema } = mongoose
const WidgetSchema = require('./WidgetSchema')
Copy link
Contributor

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?

@@ -0,0 +1,10 @@
const mongoose = require('mongoose')
const Schema = mongoose.Schema
Copy link
Contributor

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",
Copy link
Contributor

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...)

})

router.post('/dashboards/:id/widgets', (request, response, next ) => {
Widget.create(request.body, (error, post) => {
Copy link
Contributor

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

})
})

router.put('/:userId/widgets/:widgetId', ( request, response, next ) => {
Copy link
Contributor

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.

)
})

router.delete( '/:userId/widgets/:widgetId', ( request, response, next ) => {
Copy link
Contributor

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')
Copy link
Contributor

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 )
Copy link
Contributor

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.

Copy link
Contributor

@jrobcodes jrobcodes left a 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)
Copy link
Contributor

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')
Copy link
Contributor

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 ) => {
Copy link
Contributor

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) => {
Copy link
Contributor

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 )
Copy link
Contributor

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 )
Copy link
Contributor

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")
Copy link
Contributor

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.

Copy link
Contributor Author

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.

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.

Copy link
Contributor

@jrobcodes jrobcodes left a 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
Copy link
Contributor

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 );
Copy link
Contributor

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 ) {
Copy link
Contributor

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.

Copy link
Contributor

@jrobcodes jrobcodes left a 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
Copy link
Contributor

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
Copy link
Contributor

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 ) )
Copy link
Contributor

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 ) => {
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants