Files
doc_ai_backed/api/v1/task/handler.go
2025-12-10 23:17:24 +08:00

62 lines
1.6 KiB
Go

package task
import (
"net/http"
"gitea.com/bitwsd/document_ai/pkg/log"
"gitea.com/bitwsd/document_ai/internal/model/task"
"gitea.com/bitwsd/document_ai/internal/service"
"gitea.com/bitwsd/document_ai/pkg/common"
"github.com/gin-gonic/gin"
)
type TaskEndpoint struct {
taskService *service.TaskService
}
func NewTaskEndpoint() *TaskEndpoint {
return &TaskEndpoint{taskService: service.NewTaskService()}
}
func (h *TaskEndpoint) EvaluateTask(c *gin.Context) {
var req task.EvaluateTaskRequest
if err := c.ShouldBindJSON(&req); err != nil {
log.Error(c, "func", "EvaluateTask", "msg", "Invalid parameters", "error", err)
c.JSON(http.StatusOK, common.ErrorResponse(c, common.CodeParamError, "Invalid parameters"))
return
}
err := h.taskService.EvaluateTask(c, &req)
if err != nil {
c.JSON(http.StatusOK, common.ErrorResponse(c, common.CodeSystemError, "评价任务失败"))
return
}
c.JSON(http.StatusOK, common.SuccessResponse(c, nil))
}
func (h *TaskEndpoint) GetTaskList(c *gin.Context) {
var req task.TaskListRequest
if err := c.ShouldBindQuery(&req); err != nil {
log.Error(c, "func", "GetTaskList", "msg", "Invalid parameters", "error", err)
c.JSON(http.StatusOK, common.ErrorResponse(c, common.CodeParamError, "Invalid parameters"))
return
}
if req.Page <= 0 {
req.Page = 1
}
if req.PageSize <= 0 {
req.PageSize = 10
}
resp, err := h.taskService.GetTaskList(c, &req)
if err != nil {
c.JSON(http.StatusOK, common.ErrorResponse(c, common.CodeSystemError, "获取任务列表失败"))
return
}
c.JSON(http.StatusOK, common.SuccessResponse(c, resp))
}