fixed bug where you could comment on non existant blog posts

This commit is contained in:
rawleyIfowler
2022-03-02 13:56:36 -06:00
parent 22811c8b0a
commit 0ffe1cf33d
2 changed files with 7 additions and 2 deletions

View File

@@ -72,6 +72,7 @@ func RenderIndividualBlogPost(c *gin.Context) {
bp := GetBlogPostById(c.Param("url"))
if bp == nil {
c.HTML(http.StatusNotFound, "not_found.tmpl", models.Page{Title: "404"})
return
} else {
// Blog posts handle the title themselves
c.HTML(http.StatusOK, "blog_post.tmpl", struct {
@@ -147,9 +148,9 @@ func GetAllBlogPosts() *[]models.BlogPost {
}
func GetBlogPostById(id string) *models.BlogPost {
var post models.BlogPost
var post models.BlogPost = models.BlogPost{}
err := db.Model(&post).Where(&models.BlogPost{Url: id}).Find(&post).Error
if err != nil {
if err != nil || post.Equals(&models.BlogPost{}) {
return nil
}
// TODO: Figure out gorm joins!