init repo
This commit is contained in:
61
api/v1/task/handler.go
Normal file
61
api/v1/task/handler.go
Normal file
@@ -0,0 +1,61 @@
|
||||
package task
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"gitea.com/bitwsd/core/common/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))
|
||||
}
|
||||
11
api/v1/task/router.go
Normal file
11
api/v1/task/router.go
Normal file
@@ -0,0 +1,11 @@
|
||||
package task
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func SetupRouter(engine *gin.RouterGroup) {
|
||||
endpoint := NewTaskEndpoint()
|
||||
engine.POST("/task/evaluate", endpoint.EvaluateTask)
|
||||
engine.GET("/task/list", endpoint.GetTaskList)
|
||||
}
|
||||
Reference in New Issue
Block a user