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

Connor's Personal API #33

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open

Connor's Personal API #33

wants to merge 6 commits into from

Conversation

conmart
Copy link

@conmart conmart commented Sep 5, 2017

No description provided.

success: renderMultipleGames
});

// Displays new game form on click

Choose a reason for hiding this comment

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

next bunch of lines should be indented

event.preventDefault();
let formData = $(this).serialize();

// console.log(formData);

Choose a reason for hiding this comment

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

unused code

</div>
`
$('.display-games').prepend(newHTML);
// console.log(game._id);

Choose a reason for hiding this comment

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

more commented out code

Choose a reason for hiding this comment

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

there's a bunch of these commented out console logs. I won't mark all of them

url: putURL,
data: updatedGameData,

// success: function(msg){

Choose a reason for hiding this comment

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

commented out code

endpoints: [
{method: "GET", path: "/api", description: "Describes all available endpoints"},
{method: "GET", path: "/api/profile", description: "Data about me"}, // CHANGE ME
{method: "POST", path: "/api/campsites", description: "E.g. Create a new campsite"} // CHANGE ME
{method: "GET", path: "/api/profile", description: "A little information about me"},

Choose a reason for hiding this comment

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

add in all your routes for /api/boardgames

Copy link

@mnfmnfm mnfmnfm left a comment

Choose a reason for hiding this comment

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

Really nice work.

if (err) {
console.log('ERROR from controller create', err);
}
if (game.image) {
Copy link

Choose a reason for hiding this comment

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

Could think about doing this before create, so that you only have a single database transaction:

if (!req.body.image) {
  req.body.image = 'images/generic-game-image.jpg';
}
db.Boardgame.create(...

game.image = 'images/generic-game-image.jpg';
game.save(function(err, newGame) {
if (err) {
console.log("ERROR from update controller", err);
Copy link

Choose a reason for hiding this comment

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

this is clearly copy-pasted from update, with now-incorrect comments

// Updates edited game
function update (req, res) {
db.Boardgame.findById(req.params.id, function(err, foundGame) {
foundGame.title = req.body.title,
Copy link

Choose a reason for hiding this comment

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

commas 😭 these should each be their own line of code, with a semicolon

function destroy (req, res) {
db.Boardgame.findByIdAndRemove(req.params.id, function(err, deletedGame) {
if (err) {
console.log(err);
Copy link

Choose a reason for hiding this comment

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

even if there's an error, would be nice to send back some response



app.get('/api/boardgames', controllers.boardgames.index);
app.post('/api/newBoardgame', controllers.boardgames.create);
Copy link

Choose a reason for hiding this comment

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

standard REST conventions say this should just be a POST to /api/boardgames

<div class="col-md-6 col-md-offset-3 display-games">
<!-- start of one game item -->
<!-- Test display with one game -->
<!-- <div class="card" style="width: 45rem;">
Copy link

Choose a reason for hiding this comment

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

This commented-out code is now captured in your app.js file; can be removed from here to keep this file less cluttered

</div>

<div class="form-group row">
<label for="example-text-input" class="col-2 col-form-label">Image</label>
Copy link

Choose a reason for hiding this comment

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

label for is supposed to be for the id of the input the label points at--you need to add IDs to the inputs and make the for equal to that ID.

})

// Allows user to go back to main view from new game form
$('#cancel-btn').on('click', function(event) {
Copy link

Choose a reason for hiding this comment

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

This callback and the above could use the same function (could prevent default on both and call toggle; then you'd only need to write such a function once)

})

// Creates new game on submit
$('.new-game-form').on('submit', function(event) {
Copy link

Choose a reason for hiding this comment

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

This is the only longer, data-sending callback that you write inline--it would be better to be consistent, and define this method where you define handleEditGame/handleUpdateGame/etc.


renderOneGame(updatedGame);

$('[data-game-id =' + gameId + ']')[0].scrollIntoView();
Copy link

Choose a reason for hiding this comment

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

this is such a cool method!

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