2026-04-17 14:09:02 +08:00
|
|
|
// Package handler provides HTTP handlers for various endpoints.
|
|
|
|
|
package handler
|
|
|
|
|
|
|
|
|
|
import (
|
2026-04-28 17:41:28 +08:00
|
|
|
"modelRT/constants"
|
2026-04-17 14:09:02 +08:00
|
|
|
"modelRT/database"
|
|
|
|
|
"modelRT/logger"
|
|
|
|
|
"modelRT/network"
|
|
|
|
|
|
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// AsyncTaskProgressUpdateHandler handles updating task progress (internal use, not exposed via API)
|
|
|
|
|
func AsyncTaskProgressUpdateHandler(c *gin.Context) {
|
|
|
|
|
ctx := c.Request.Context()
|
|
|
|
|
var request network.AsyncTaskProgressUpdate
|
|
|
|
|
|
|
|
|
|
if err := c.ShouldBindJSON(&request); err != nil {
|
|
|
|
|
logger.Error(ctx, "failed to unmarshal async task progress update request", "error", err)
|
2026-04-28 17:41:28 +08:00
|
|
|
renderRespFailure(c, constants.RespCodeInvalidParams, "invalid request parameters", nil)
|
2026-04-17 14:09:02 +08:00
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pgClient := database.GetPostgresDBClient()
|
|
|
|
|
if pgClient == nil {
|
|
|
|
|
logger.Error(ctx, "database connection not found in context")
|
2026-04-28 17:41:28 +08:00
|
|
|
renderRespFailure(c, constants.RespCodeServerError, "database connection error", nil)
|
2026-04-17 14:09:02 +08:00
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
err := database.UpdateAsyncTaskProgress(ctx, pgClient, request.TaskID, request.Progress)
|
|
|
|
|
if err != nil {
|
|
|
|
|
logger.Error(ctx, "failed to update async task progress", "task_id", request.TaskID, "error", err)
|
2026-04-28 17:41:28 +08:00
|
|
|
renderRespFailure(c, constants.RespCodeServerError, "failed to update task progress", nil)
|
2026-04-17 14:09:02 +08:00
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-28 17:41:28 +08:00
|
|
|
renderRespSuccess(c, constants.RespCodeSuccess, "task progress updated successfully", nil)
|
2026-04-17 14:09:02 +08:00
|
|
|
}
|