This commit is contained in:
2026-06-21 20:01:20 +08:00
parent 62732ba348
commit 42516257e0
9 changed files with 179 additions and 18 deletions
+12 -1
View File
@@ -4,16 +4,27 @@ import (
"net/http"
"github.com/gin-gonic/gin"
"go_blog/models"
"gorm.io/gorm"
)
// AdminDashboard renders the protected admin dashboard.
func AdminDashboard() gin.HandlerFunc {
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)
}
}