//PostDelete handles POST /admin/posts/:id/delete route func PostDelete(c *gin.Context) { post, _ := models.GetPost(c.Param("id")) if err := post.Delete(); err != nil { c.HTML(http.StatusInternalServerError, "errors/500", nil) logrus.Error(err) return } c.Redirect(http.StatusFound, "/admin/posts") }
//PostGet handles GET /posts/:id route func PostGet(c *gin.Context) { post, err := models.GetPost(c.Param("id")) if err != nil || !post.Published { c.HTML(http.StatusNotFound, "errors/404", nil) return } h := helpers.DefaultH(c) h["Title"] = post.Name h["Description"] = template.HTML(string(blackfriday.MarkdownCommon([]byte(post.Description)))) h["Post"] = post h["Active"] = fmt.Sprintf("posts/%d", post.ID) c.HTML(http.StatusOK, "posts/show", h) }
//PostEdit handles GET /admin/posts/:id/edit route func PostEdit(c *gin.Context) { post, _ := models.GetPost(c.Param("id")) if post.ID == 0 { c.HTML(http.StatusNotFound, "errors/404", nil) return } tags, _ := models.GetTags() h := helpers.DefaultH(c) h["Title"] = "Edit post entry" h["Active"] = "posts" h["Post"] = post h["Tags"] = tags session := sessions.Default(c) h["Flash"] = session.Flashes() session.Save() c.HTML(http.StatusOK, "posts/form", h) }