-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c8da666
commit af535b9
Showing
12 changed files
with
3,223 additions
and
510 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,8 @@ | ||
# zbputils | ||
ZeroBot-Plugin 的工具库 | ||
|
||
swag初始化 | ||
|
||
``` | ||
swag init -g control/web/gui.go -o control/web/docs/ | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
package controller | ||
|
||
import ( | ||
"net/http" | ||
|
||
"github.com/FloatTech/zbputils/control/web/types" | ||
"github.com/FloatTech/zbputils/job" | ||
"github.com/gin-gonic/gin" | ||
) | ||
|
||
// JobList 任务列表 | ||
// | ||
// @Tags 任务 | ||
// @Summary 任务列表 | ||
// @Description 任务列表 | ||
// @Router /api/job/list [get] | ||
// @Success 200 {object} types.Response{result=[]job.Job} "成功" | ||
func JobList(context *gin.Context) { | ||
rsp, err := job.List() | ||
if err != nil { | ||
context.JSON(http.StatusOK, types.Response{ | ||
Code: -1, | ||
Result: nil, | ||
Message: err.Error(), | ||
ResponseType: "error", | ||
}) | ||
return | ||
} | ||
context.JSON(http.StatusOK, types.Response{ | ||
Code: 0, | ||
Result: rsp, | ||
Message: "", | ||
ResponseType: "ok", | ||
}) | ||
} | ||
|
||
// JobAdd 添加任务 | ||
// | ||
// @Tags 任务 | ||
// @Summary 添加任务 | ||
// @Description 添加任务 | ||
// @Router /api/job/add [post] | ||
// @Param object body job.Job false "添加任务入参" | ||
// @Success 200 {object} types.Response "成功" | ||
func JobAdd(context *gin.Context) { | ||
var ( | ||
j job.Job | ||
) | ||
err := context.ShouldBind(&j) | ||
if err != nil { | ||
context.JSON(http.StatusOK, types.Response{ | ||
Code: -1, | ||
Result: nil, | ||
Message: err.Error(), | ||
ResponseType: "error", | ||
}) | ||
return | ||
} | ||
err = job.Add(&j) | ||
if err != nil { | ||
context.JSON(http.StatusOK, types.Response{ | ||
Code: -1, | ||
Result: nil, | ||
Message: err.Error(), | ||
ResponseType: "error", | ||
}) | ||
return | ||
} | ||
context.JSON(http.StatusOK, types.Response{ | ||
Code: 0, | ||
Result: nil, | ||
Message: "", | ||
ResponseType: "ok", | ||
}) | ||
} | ||
|
||
// JobDelete 删除任务 | ||
// | ||
// @Tags 任务 | ||
// @Summary 删除任务 | ||
// @Description 删除任务 | ||
// @Router /api/job/delete [post] | ||
// @Param object body job.DeleteReq false "删除任务的入参" | ||
// @Success 200 {object} types.Response "成功" | ||
func JobDelete(context *gin.Context) { | ||
var ( | ||
req job.DeleteReq | ||
) | ||
err := context.ShouldBind(&req) | ||
if err != nil { | ||
context.JSON(http.StatusOK, types.Response{ | ||
Code: -1, | ||
Result: nil, | ||
Message: err.Error(), | ||
ResponseType: "error", | ||
}) | ||
return | ||
} | ||
err = job.Delete(&req) | ||
if err != nil { | ||
context.JSON(http.StatusOK, types.Response{ | ||
Code: -1, | ||
Result: nil, | ||
Message: err.Error(), | ||
ResponseType: "error", | ||
}) | ||
return | ||
} | ||
context.JSON(http.StatusOK, types.Response{ | ||
Code: 0, | ||
Result: nil, | ||
Message: "", | ||
ResponseType: "ok", | ||
}) | ||
} |
Oops, something went wrong.