cron.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. package cron
  2. import (
  3. "net/http"
  4. "github.com/xinliangnote/go-gin-api/internal/code"
  5. "github.com/xinliangnote/go-gin-api/internal/pkg/core"
  6. "github.com/xinliangnote/go-gin-api/internal/repository/mysql"
  7. "github.com/xinliangnote/go-gin-api/internal/repository/redis"
  8. "go.uber.org/zap"
  9. )
  10. type handler struct {
  11. logger *zap.Logger
  12. cache redis.Repo
  13. db mysql.Repo
  14. }
  15. func New(logger *zap.Logger, db mysql.Repo, cache redis.Repo) *handler {
  16. return &handler{
  17. logger: logger,
  18. cache: cache,
  19. db: db,
  20. }
  21. }
  22. func (h *handler) Add() core.HandlerFunc {
  23. return func(ctx core.Context) {
  24. ctx.HTML("cron_task_add", nil)
  25. }
  26. }
  27. func (h *handler) Edit() core.HandlerFunc {
  28. type editRequest struct {
  29. Id string `uri:"id"` // 主键ID
  30. }
  31. type editResponse struct {
  32. HashID string `json:"hash_id"` // hashID
  33. }
  34. return func(ctx core.Context) {
  35. req := new(editRequest)
  36. if err := ctx.ShouldBindURI(req); err != nil {
  37. ctx.AbortWithError(core.Error(
  38. http.StatusBadRequest,
  39. code.ParamBindError,
  40. code.Text(code.ParamBindError)).WithError(err),
  41. )
  42. return
  43. }
  44. obj := new(editResponse)
  45. obj.HashID = req.Id
  46. ctx.HTML("cron_task_edit", obj)
  47. }
  48. }
  49. func (h *handler) List() core.HandlerFunc {
  50. return func(ctx core.Context) {
  51. ctx.HTML("cron_task_list", nil)
  52. }
  53. }