Wrapping it up

Let's do a quick recap of all of the changes we've made to this controller:

  • We updated the index function to retrieve an image from MongoDB and populate viewModel with the details of the image model. We also found
    all the comments related to that image and attached an array of those to viewModel as well.
  • We tweaked the create function to insert a new image model into the database once it has been successfully renamed and saved to the filesystem.
  • The like function was updated to actually increment the value of an image's likes property and save that value to the database, as well as to return the new value via a JSON response.
  • Comments are now inserted for a particular image via the comment function. Not only is a comment model inserted into the database, but its corresponding image is also found and the image model's _id value is attached to the comment to solidify a relationship.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.73.207