feat(kol): dashboard service + API
This commit is contained in:
@@ -0,0 +1,90 @@
|
||||
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
|
||||
}
|
||||
@@ -74,6 +74,12 @@ func RegisterRoutes(app *bootstrap.App) {
|
||||
kolManage.POST("/assist", kolManageHandler.AssistSubmit)
|
||||
kolManage.GET("/assist/:id", kolManageHandler.AssistGet)
|
||||
|
||||
kolDash := protected.Group("/tenant/kol/dashboard")
|
||||
kolDashboardHandler := NewKolDashboardHandler(app)
|
||||
kolDash.GET("/overview", kolDashboardHandler.Overview)
|
||||
kolDash.GET("/packages", kolDashboardHandler.Packages)
|
||||
kolDash.GET("/trend", kolDashboardHandler.Trend)
|
||||
|
||||
kolMarketplace := protected.Group("/tenant/kol/marketplace")
|
||||
kolMarketplaceHandler := NewKolMarketplaceHandler(app)
|
||||
kolMarketplace.GET("/packages", kolMarketplaceHandler.ListPackages)
|
||||
|
||||
Reference in New Issue
Block a user