added comment posted screen
This commit is contained in:
@@ -95,12 +95,23 @@ func CreateComment(c *gin.Context) {
|
|||||||
c.Status(http.StatusNotAcceptable)
|
c.Status(http.StatusNotAcceptable)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
a := []string{c.Request.Form.Get("author"),
|
||||||
|
c.Request.Form.Get("content"),
|
||||||
|
c.Request.Form.Get("url")}
|
||||||
|
for _, v := range a {
|
||||||
|
if len(v) == 0 {
|
||||||
|
c.Status(http.StatusNotAcceptable)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
comment := models.Comment{
|
comment := models.Comment{
|
||||||
Author: c.Request.Form.Get("author"),
|
Author: a[0],
|
||||||
Content: c.Request.Form.Get("content"),
|
Content: a[1],
|
||||||
AssociatedPost: c.Request.Form.Get("url"),
|
AssociatedPost: a[2],
|
||||||
}
|
}
|
||||||
db.Create(&comment)
|
db.Create(&comment)
|
||||||
|
// Pass the associated post to the template to add to the href
|
||||||
|
c.HTML(http.StatusOK, "comment_post.tmpl", struct{ Url string }{Url: comment.AssociatedPost})
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetAllBlogPosts() *[]models.BlogPost {
|
func GetAllBlogPosts() *[]models.BlogPost {
|
||||||
|
|||||||
5
templates/comment_post.tmpl
Normal file
5
templates/comment_post.tmpl
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
{{ template "header.tmpl" . }}
|
||||||
|
<h2>Your comment is being posted...</h2>
|
||||||
|
<p>Click <a href="/blog/post/{{ .Url }}">here</a> to return to the blog post.</p>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
Reference in New Issue
Block a user