package handlers import ( "net/http" "github.com/gin-gonic/gin" "go_blog/models" "gorm.io/gorm" ) // AdminDashboard renders the protected admin dashboard. func AdminDashboard(db *gorm.DB) gin.HandlerFunc { return func(c *gin.Context) { tr := getTr(c) username, _ := c.Get("username") data := DefaultData(c) data["Title"] = tr["dash_page_title"] data["Username"] = username // Article counts: total and published. var postCount, publishedCount int64 db.Model(&models.Article{}).Count(&postCount) db.Model(&models.Article{}).Where("status = ?", models.ArticlePublished).Count(&publishedCount) data["PostCount"] = postCount data["PublishedCount"] = publishedCount c.HTML(http.StatusOK, "dashboard", data) } }