12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- 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)
- }
- }
|