Commit 7386665c authored by Rafael's avatar Rafael

bugfix: do not show posts not published

parent f38e61e5
Pipeline #20588779 passed with stage
......@@ -209,9 +209,11 @@ func GetPosts(category string, page int32) []map[string]interface{} {
db := database.DBCon
postsArray := make([]map[string]interface{}, 0, 4)
var categoryFilter string
var whereClause string
if category != "" {
categoryFilter = "WHERE blog_category.slug = ?"
whereClause = "WHERE blog_category.slug = ? AND blog_post.published_at IS NOT NULL"
} else {
whereClause = "WHERE blog_post.published_at IS NOT NULL"
}
query := `SELECT blog_post.id, blog_post.slug, blog_post.title, blog_post.content,
......@@ -222,7 +224,7 @@ func GetPosts(category string, page int32) []map[string]interface{} {
ON blog_category.id = blog_post.category_id
INNER JOIN auth_user
ON auth_user.id = blog_post.author_id
` + categoryFilter + `
` + whereClause + `
ORDER BY blog_post.published_at DESC
LIMIT 4 OFFSET ?
`
......@@ -553,12 +555,14 @@ func GetNumberOfPages(category string) int32 {
INNER JOIN blog_category
ON blog_category.id = blog_post.category_id
WHERE blog_category.slug = ? AND
published_at < NOW()`
blog_post.published_at < NOW() AND
blog_post.published_at IS NOT NULL`
rows, err = db.Query(query, category)
} else {
query = `SELECT COUNT(*)
FROM blog_post
WHERE published_at < NOW()`
WHERE published_at < NOW() AND
published_at IS NOT NULL`
rows, err = db.Query(query)
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment