@@ -42,31 +42,30 @@ router.get("/blog/:id", function(req, res) {
42
42
} )
43
43
} )
44
44
45
- // // EDIT
46
- // router.get("/:id/edit", middleware.checkCampgroundOwnership , function(req, res){
47
- // Campground .findById(req.params.id, function(err, foundCampground ){
48
- // if(err){
49
- // res.redirect("/campgrounds ")
50
- // } else{
51
- // res.render("campgrounds /edit", {campground: foundCampground })
52
- // }
53
- // })
54
- // })
45
+ //EDIT
46
+ router . get ( "/blog/ :id/edit" , middleware . checkBlogOwnership , function ( req , res ) {
47
+ Blog . findById ( req . params . id , function ( err , foundBlog ) {
48
+ if ( err ) {
49
+ res . redirect ( "/" )
50
+ } else {
51
+ res . render ( "blogs /edit" , { blog : foundBlog } )
52
+ }
53
+ } )
54
+ } )
55
55
56
- // // UPDATE
57
- // router.put("/:id", middleware.checkCampgroundOwnership , function(req, res){
58
- // Campground .findByIdAndUpdate(req.params.id, req.body.cmp , function(err, updatedCmp ){
59
- // if(err){
60
- // res.redirect("/campgrounds ")
61
- // } else{
62
- // res.redirect("/campgrounds /" + req.params.id)
63
- // }
64
- // })
65
- // })
56
+ //UPDATE
57
+ router . put ( "/blog/ :id" , middleware . checkBlogOwnership , function ( req , res ) {
58
+ Blog . findByIdAndUpdate ( req . params . id , req . body . blog , function ( err , updatedBlog ) {
59
+ if ( err ) {
60
+ res . redirect ( "/" )
61
+ } else {
62
+ res . redirect ( "/blog /" + req . params . id )
63
+ }
64
+ } )
65
+ } )
66
66
67
67
//DELETE
68
68
router . delete ( "/blog/:id" , function ( req , res ) {
69
- console . log ( "routed to delte" )
70
69
Blog . findByIdAndRemove ( req . params . id , function ( err ) {
71
70
if ( err ) {
72
71
console . log ( err )
0 commit comments