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

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>