|
- package http
-
- import (
- "net/http"
-
- "github.com/gin-gonic/gin"
- "gitlink.org.cn/cloudream/jcs-pub/client/internal/http/types"
- cliapi "gitlink.org.cn/cloudream/jcs-pub/client/sdk/api/v1"
- "gitlink.org.cn/cloudream/jcs-pub/common/ecode"
- )
-
- type TickTockService struct {
- *Server
- }
-
- func (s *Server) TickTock() *TickTockService {
- return &TickTockService{s}
- }
-
- func (s *TickTockService) ListJobs(ctx *gin.Context) {
- var req cliapi.TickTockListJobs
- if err := ctx.ShouldBindQuery(&req); err != nil {
- ctx.JSON(http.StatusBadRequest, types.Failed(ecode.BadArgument, "%v", err))
- return
- }
-
- names := s.svc.TickTock.GetJobNames()
- ctx.JSON(http.StatusOK, types.OK(cliapi.TickTockListJobsResp{
- Jobs: names,
- }))
- }
-
- func (s *TickTockService) RunJob(ctx *gin.Context) {
- var req cliapi.TickTockRunJob
- if err := ctx.ShouldBindJSON(&req); err != nil {
- ctx.JSON(http.StatusBadRequest, types.Failed(ecode.BadArgument, "%v", err))
- return
- }
-
- if !s.svc.TickTock.RunNow(req.Name) {
- ctx.JSON(http.StatusOK, types.Failed(ecode.DataNotFound, "job %s not found", req.Name))
- return
- }
-
- ctx.JSON(http.StatusOK, types.OK(cliapi.TickTockRunJobResp{}))
- }
|