Files
go-gin-api/internal/render/cron/cron.go
T
新亮 4c37a7e6b5 feature(1.2.8): swagger 接口文档新增 Security
- 将 middleware 命名为 interceptor
- 将 deploy 命名为 deployments
- 移除 pkg/errno
- 使用 proposal 目录
- 优化代码
2021-11-28 13:25:27 +08:00

65 lines
1.3 KiB
Go

package cron
import (
"net/http"
"github.com/xinliangnote/go-gin-api/internal/code"
"github.com/xinliangnote/go-gin-api/internal/pkg/core"
"github.com/xinliangnote/go-gin-api/internal/repository/mysql"
"github.com/xinliangnote/go-gin-api/internal/repository/redis"
"go.uber.org/zap"
)
type handler struct {
logger *zap.Logger
cache redis.Repo
db mysql.Repo
}
func New(logger *zap.Logger, db mysql.Repo, cache redis.Repo) *handler {
return &handler{
logger: logger,
cache: cache,
db: db,
}
}
func (h *handler) Add() core.HandlerFunc {
return func(ctx core.Context) {
ctx.HTML("cron_task_add", nil)
}
}
func (h *handler) Edit() core.HandlerFunc {
type editRequest struct {
Id string `uri:"id"` // 主键ID
}
type editResponse struct {
HashID string `json:"hash_id"` // hashID
}
return func(ctx core.Context) {
req := new(editRequest)
if err := ctx.ShouldBindURI(req); err != nil {
ctx.AbortWithError(core.Error(
http.StatusBadRequest,
code.ParamBindError,
code.Text(code.ParamBindError)).WithError(err),
)
return
}
obj := new(editResponse)
obj.HashID = req.Id
ctx.HTML("cron_task_edit", obj)
}
}
func (h *handler) List() core.HandlerFunc {
return func(ctx core.Context) {
ctx.HTML("cron_task_list", nil)
}
}