Skip to content
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

Create rating api #30

Merged
22 changes: 22 additions & 0 deletions backend/controllers/rate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Load required packages
var Rate = require('../models/history.js');
Copy link
Contributor

Choose a reason for hiding this comment

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

line 2: variable naming convention should be lowerCamelCase


// Create endpoint /api/ratings for POST
exports.postRates = function (req, res) {
var movieId = req.body.movieId;
var score = req.body.score;
var userId = req.user.id;
// Save the rating and check for errors
Rate.build({score: score, movie_id: movieId, user_id: userId})
.save().then(function (success) {
res.json({message: 'Ratings successfully posted!'});
Copy link
Contributor

@Shadowsong27 Shadowsong27 Feb 12, 2017

Choose a reason for hiding this comment

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

line 12: JSON format, I think break lines around curly brackets should be used, even though it is just one line json

});
};

// Create endpoint /api/ratings for GET
exports.getRates = function (req, res) {
// Use the Ratings model to find all clients
Rate.findAll({where: {user_id: req.user.id}}).then(function(ratings){
Copy link
Contributor

@Shadowsong27 Shadowsong27 Feb 12, 2017

Choose a reason for hiding this comment

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

same as above

res.json(ratings);
});
};
5 changes: 5 additions & 0 deletions backend/routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ var authController = require('../controllers/auth');
var oauth2Controller = require('../controllers/oauth2');
var clientController = require('../controllers/client');
var movieController = require('../controllers/movie');
var ratingController = require('../controllers/rate');

// on routes that end in /users
// ----------------------------------------------------
Expand Down Expand Up @@ -75,4 +76,8 @@ router.route('/movies/year')
.get(authController.isAuthenticated,
movieController.getMoviesByProductionYear);

router.route('/ratings')
.post(authController.isAuthenticated, ratingController.postRates)
.get(authController.isAuthenticated, ratingController.getRates);

module.exports = router;