package transport import ( "strconv" "github.com/gin-gonic/gin" "github.com/geo-platform/tenant-api/internal/bootstrap" "github.com/geo-platform/tenant-api/internal/shared/response" "github.com/geo-platform/tenant-api/internal/tenant/app" "github.com/geo-platform/tenant-api/internal/tenant/repository" ) type KolDashboardHandler struct { svc *app.KolDashboardService } func NewKolDashboardHandler(a *bootstrap.App) *KolDashboardHandler { profileSvc := app.NewKolProfileService(a.KolProfiles) return &KolDashboardHandler{ svc: app.NewKolDashboardService( profileSvc, a.KolPackages, a.KolSubscriptions, repository.NewKolUsageRepository(a.DB), ), } } func (h *KolDashboardHandler) Overview(c *gin.Context) { actor, ok := actorFromRequest(c) if !ok { return } data, err := h.svc.Overview(c.Request.Context(), actor) if err != nil { response.Error(c, err) return } response.Success(c, data) } func (h *KolDashboardHandler) Packages(c *gin.Context) { actor, ok := actorFromRequest(c) if !ok { return } data, err := h.svc.PerPackage(c.Request.Context(), actor) if err != nil { response.Error(c, err) return } response.Success(c, data) } func (h *KolDashboardHandler) Trend(c *gin.Context) { actor, ok := actorFromRequest(c) if !ok { return } periodDays := parseKolDashboardPeriodDays(c.Query("period_days")) if err := app.ValidateKolDashboardPeriodDays(periodDays); err != nil { response.Error(c, err) return } data, err := h.svc.Trend(c.Request.Context(), actor, periodDays) if err != nil { response.Error(c, err) return } response.Success(c, data) } func parseKolDashboardPeriodDays(value string) int { if value == "" { return 7 } parsed, err := strconv.Atoi(value) if err != nil { return 0 } return parsed }