Files
license/internal/httpapi/dashboard_handler.go
2026-07-31 16:59:55 +08:00

39 lines
1.0 KiB
Go

package httpapi
import (
"net/http"
"github.com/gin-gonic/gin"
"git.apinb.com/ops/license/internal/dashboard"
)
type dashboardHandler struct {
service *dashboard.Service
}
type dashboardView struct {
SubjectCount int64 `json:"subject_count"`
IssuanceCount int64 `json:"issuance_count"`
ExpiringSoonCount int64 `json:"expiring_soon_count"`
RecentIssuances []issuanceSummaryView `json:"recent_issuances"`
}
func (h dashboardHandler) get(c *gin.Context) {
overview, err := h.service.Get(c.Request.Context())
if err != nil {
writeError(c, err)
return
}
recent := make([]issuanceSummaryView, len(overview.RecentIssuances))
for index := range overview.RecentIssuances {
recent[index] = newIssuanceSummaryView(overview.RecentIssuances[index])
}
writeData(c, http.StatusOK, dashboardView{
SubjectCount: overview.SubjectCount,
IssuanceCount: overview.IssuanceCount,
ExpiringSoonCount: overview.ExpiringSoonCount,
RecentIssuances: recent,
})
}