handler.go 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. package cron
  2. import (
  3. "github.com/xinliangnote/go-gin-api/configs"
  4. "github.com/xinliangnote/go-gin-api/internal/pkg/core"
  5. cronRepo "github.com/xinliangnote/go-gin-api/internal/repository/cron"
  6. "github.com/xinliangnote/go-gin-api/internal/repository/mysql"
  7. "github.com/xinliangnote/go-gin-api/internal/repository/redis"
  8. "github.com/xinliangnote/go-gin-api/internal/services/cron"
  9. "github.com/xinliangnote/go-gin-api/pkg/hash"
  10. "go.uber.org/zap"
  11. )
  12. var _ Handler = (*handler)(nil)
  13. type Handler interface {
  14. i()
  15. // Create 创建任务
  16. // @Tags API.cron
  17. // @Router /api/cron [post]
  18. Create() core.HandlerFunc
  19. // Modify 编辑任务
  20. // @Tags API.cron
  21. // @Router /api/cron/{id} [post]
  22. Modify() core.HandlerFunc
  23. // List 任务列表
  24. // @Tags API.cron
  25. // @Router /api/cron [get]
  26. List() core.HandlerFunc
  27. // UpdateUsed 更新任务为启用/禁用
  28. // @Tags API.cron
  29. // @Router /api/cron/used [patch]
  30. UpdateUsed() core.HandlerFunc
  31. // Detail 获取单条任务详情
  32. // @Tags API.cron
  33. // @Router /api/cron/{id} [get]
  34. Detail() core.HandlerFunc
  35. // Execute 手动执行任务
  36. // @Tags API.cron
  37. // @Router /api/cron/{id} [patch]
  38. Execute() core.HandlerFunc
  39. }
  40. type handler struct {
  41. logger *zap.Logger
  42. cache redis.Repo
  43. hashids hash.Hash
  44. cronService cron.Service
  45. }
  46. func New(logger *zap.Logger, db mysql.Repo, cache redis.Repo, cronServer cronRepo.Server) Handler {
  47. return &handler{
  48. logger: logger,
  49. cache: cache,
  50. hashids: hash.New(configs.Get().HashIds.Secret, configs.Get().HashIds.Length),
  51. cronService: cron.New(db, cache, cronServer),
  52. }
  53. }
  54. func (h *handler) i() {}