From dca2efc52dfc6534695acfd47410287eae6e57f9 Mon Sep 17 00:00:00 2001 From: rawleyIfowler Date: Fri, 25 Feb 2022 18:36:02 -0600 Subject: [PATCH] added comment posted screen --- controllers/blog.go | 17 ++++++++++++++--- templates/comment_post.tmpl | 5 +++++ 2 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 templates/comment_post.tmpl diff --git a/controllers/blog.go b/controllers/blog.go index a2ebfbf..f4c9b3a 100644 --- a/controllers/blog.go +++ b/controllers/blog.go @@ -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 { diff --git a/templates/comment_post.tmpl b/templates/comment_post.tmpl new file mode 100644 index 0000000..799b080 --- /dev/null +++ b/templates/comment_post.tmpl @@ -0,0 +1,5 @@ +{{ template "header.tmpl" . }} +

Your comment is being posted...

+

Click here to return to the blog post.

+ +