You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
105 lines
2.4 KiB
105 lines
2.4 KiB
package handler
|
|
|
|
import (
|
|
"github.com/gin-gonic/gin"
|
|
|
|
"laic-backend/common"
|
|
"laic-backend/service"
|
|
"laic-backend/vo"
|
|
)
|
|
|
|
// GetTaskPage 任务分页列表
|
|
func GetTaskPage(c *gin.Context) {
|
|
var req vo.TaskPageReq
|
|
_ = c.ShouldBindQuery(&req)
|
|
if req.PageNum <= 0 {
|
|
req.PageNum = 1
|
|
}
|
|
if req.PageSize <= 0 {
|
|
req.PageSize = 10
|
|
}
|
|
page, busiErr := service.DefaultTaskService.GetPage(common.GetUserId(c), common.IsAdmin(c), &req)
|
|
if busiErr != nil {
|
|
common.FailWithBusiError(c, busiErr)
|
|
return
|
|
}
|
|
common.OKWithData(c, page)
|
|
}
|
|
|
|
// GetTask 任务详情
|
|
func GetTask(c *gin.Context) {
|
|
id, busiErr := parseStringID(c)
|
|
if busiErr != nil {
|
|
common.FailWithBusiError(c, busiErr)
|
|
return
|
|
}
|
|
task, busiErr := service.DefaultTaskService.GetDetail(common.GetUserId(c), common.IsAdmin(c), id)
|
|
if busiErr != nil {
|
|
common.FailWithBusiError(c, busiErr)
|
|
return
|
|
}
|
|
common.OKWithData(c, task)
|
|
}
|
|
|
|
// CreateTask 新增任务
|
|
func CreateTask(c *gin.Context) {
|
|
var req vo.TaskCreateReq
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
common.FailWithBindError(c, common.ErrParam, err)
|
|
return
|
|
}
|
|
task, busiErr := service.DefaultTaskService.Create(common.GetUserId(c), &req)
|
|
if busiErr != nil {
|
|
common.FailWithBusiError(c, busiErr)
|
|
return
|
|
}
|
|
common.OKWithData(c, task)
|
|
}
|
|
|
|
// UpdateTask 编辑任务
|
|
func UpdateTask(c *gin.Context) {
|
|
id, busiErr := parseStringID(c)
|
|
if busiErr != nil {
|
|
common.FailWithBusiError(c, busiErr)
|
|
return
|
|
}
|
|
var req vo.TaskUpdateReq
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
common.FailWithBindError(c, common.ErrParam, err)
|
|
return
|
|
}
|
|
if busiErr := service.DefaultTaskService.Update(common.GetUserId(c), common.IsAdmin(c), id, &req); busiErr != nil {
|
|
common.FailWithBusiError(c, busiErr)
|
|
return
|
|
}
|
|
common.OK(c)
|
|
}
|
|
|
|
// DeleteTask 删除任务
|
|
func DeleteTask(c *gin.Context) {
|
|
id, busiErr := parseStringID(c)
|
|
if busiErr != nil {
|
|
common.FailWithBusiError(c, busiErr)
|
|
return
|
|
}
|
|
if busiErr := service.DefaultTaskService.Delete(common.GetUserId(c), common.IsAdmin(c), id); busiErr != nil {
|
|
common.FailWithBusiError(c, busiErr)
|
|
return
|
|
}
|
|
common.OK(c)
|
|
}
|
|
|
|
// ExecuteTask 立即执行任务
|
|
func ExecuteTask(c *gin.Context) {
|
|
id, busiErr := parseStringID(c)
|
|
if busiErr != nil {
|
|
common.FailWithBusiError(c, busiErr)
|
|
return
|
|
}
|
|
result, busiErr := service.DefaultTaskService.Execute(common.GetUserId(c), common.IsAdmin(c), id)
|
|
if busiErr != nil {
|
|
common.FailWithBusiError(c, busiErr)
|
|
return
|
|
}
|
|
common.OKWithData(c, result)
|
|
}
|
|
|