added comment posted screen

This commit is contained in:
rawleyIfowler
2022-02-25 18:36:02 -06:00
parent 598f372acd
commit dca2efc52d
2 changed files with 19 additions and 3 deletions

View File

@@ -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 {

View 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>