feat: add track point
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"gitea.com/texpixel/document_ai/api/v1/analytics"
|
||||
"gitea.com/texpixel/document_ai/api/v1/formula"
|
||||
"gitea.com/texpixel/document_ai/api/v1/oss"
|
||||
"gitea.com/texpixel/document_ai/api/v1/task"
|
||||
@@ -47,6 +48,13 @@ func SetupRouter(engine *gin.RouterGroup) {
|
||||
userRouter.GET("/info", common.MustAuthMiddleware(), userEndpoint.GetUserInfo)
|
||||
}
|
||||
}
|
||||
|
||||
// 数据埋点路由
|
||||
analyticsRouter := v1.Group("/analytics", common.GetAuthMiddleware())
|
||||
{
|
||||
analyticsHandler := analytics.NewAnalyticsHandler()
|
||||
analyticsRouter.POST("/track", analyticsHandler.TrackEvent)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
47
api/v1/analytics/handler.go
Normal file
47
api/v1/analytics/handler.go
Normal file
@@ -0,0 +1,47 @@
|
||||
package analytics
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"gitea.com/texpixel/document_ai/internal/model/analytics"
|
||||
"gitea.com/texpixel/document_ai/internal/service"
|
||||
"gitea.com/texpixel/document_ai/pkg/common"
|
||||
"gitea.com/texpixel/document_ai/pkg/log"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type AnalyticsHandler struct {
|
||||
analyticsService *service.AnalyticsService
|
||||
}
|
||||
|
||||
func NewAnalyticsHandler() *AnalyticsHandler {
|
||||
return &AnalyticsHandler{
|
||||
analyticsService: service.NewAnalyticsService(),
|
||||
}
|
||||
}
|
||||
|
||||
// TrackEvent 记录单个事件
|
||||
// @Summary 记录单个埋点事件
|
||||
// @Description 记录用户行为埋点事件
|
||||
// @Tags Analytics
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param request body analytics.TrackEventRequest true "事件信息"
|
||||
// @Success 200 {object} common.Response
|
||||
// @Router /api/v1/analytics/track [post]
|
||||
func (h *AnalyticsHandler) TrackEvent(c *gin.Context) {
|
||||
var req analytics.TrackEventRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
log.Error(c.Request.Context(), "bind request failed", "error", err)
|
||||
c.JSON(http.StatusOK, common.ErrorResponse(c, common.CodeParamError, "invalid request"))
|
||||
return
|
||||
}
|
||||
|
||||
if err := h.analyticsService.TrackEvent(c.Request.Context(), &req); err != nil {
|
||||
log.Error(c.Request.Context(), "track event failed", "error", err)
|
||||
c.JSON(http.StatusOK, common.ErrorResponse(c, common.CodeSystemError, "failed to track event"))
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, common.SuccessResponse(c, "success"))
|
||||
}
|
||||
Reference in New Issue
Block a user