feat: add internal public overview endpoint for homepage stats

This commit is contained in:
Haitao Pan 2026-02-04 14:15:27 +08:00
parent 85a7d7e560
commit 4bbfdef8cd
2 changed files with 31 additions and 0 deletions

View File

@ -278,6 +278,11 @@ func RegisterRoutes(r *gin.Engine, opts ...Option) {
authProtected.POST("/admin/users/:userId/role", h.updateUserRole)
authProtected.DELETE("/admin/users/:userId/role", h.resetUserRole)
// Internal routes for service-to-service reads.
internalGroup := r.Group("/api/internal")
internalGroup.Use(auth.InternalAuthMiddleware())
internalGroup.GET("/public-overview", h.internalPublicOverview)
// Public /api routes for admin/management (expected by frontend at /api/admin/...)
apiGroup := r.Group("/api")
if h.tokenService != nil {

View File

@ -0,0 +1,26 @@
package api
import (
"net/http"
"time"
"github.com/gin-gonic/gin"
)
type internalPublicOverviewResponse struct {
RegisteredUsers int `json:"registeredUsers"`
UpdatedAt time.Time `json:"updatedAt"`
}
func (h *handler) internalPublicOverview(c *gin.Context) {
users, err := h.store.ListUsers(c.Request.Context())
if err != nil {
respondError(c, http.StatusInternalServerError, "list_users_failed", "failed to fetch users")
return
}
c.JSON(http.StatusOK, internalPublicOverviewResponse{
RegisteredUsers: len(users),
UpdatedAt: time.Now().UTC(),
})
}