mirror of
https://github.com/xinliangnote/go-gin-api.git
synced 2024-04-21 12:31:46 +00:00
- 将 middleware 命名为 interceptor - 将 deploy 命名为 deployments - 移除 pkg/errno - 使用 proposal 目录 - 优化代码
65 lines
1.3 KiB
Go
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)
|
|
}
|
|
}
|