added comment posted screen
This commit is contained in:
@@ -95,12 +95,23 @@ func CreateComment(c *gin.Context) {
|
||||
c.Status(http.StatusNotAcceptable)
|
||||
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{
|
||||
Author: c.Request.Form.Get("author"),
|
||||
Content: c.Request.Form.Get("content"),
|
||||
AssociatedPost: c.Request.Form.Get("url"),
|
||||
Author: a[0],
|
||||
Content: a[1],
|
||||
AssociatedPost: a[2],
|
||||
}
|
||||
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 {
|
||||
|
||||
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