admin.go 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. package admin
  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. db mysql.Repo
  12. logger *zap.Logger
  13. cache redis.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) Login() core.HandlerFunc {
  23. return func(ctx core.Context) {
  24. ctx.HTML("admin_login", nil)
  25. }
  26. }
  27. func (h *handler) Add() core.HandlerFunc {
  28. return func(ctx core.Context) {
  29. ctx.HTML("admin_add", nil)
  30. }
  31. }
  32. func (h *handler) List() core.HandlerFunc {
  33. return func(ctx core.Context) {
  34. ctx.HTML("admin_list", nil)
  35. }
  36. }
  37. func (h *handler) Menu() core.HandlerFunc {
  38. return func(ctx core.Context) {
  39. ctx.HTML("menu_view", nil)
  40. }
  41. }
  42. func (h *handler) AdminMenu() core.HandlerFunc {
  43. type adminMenuRequest struct {
  44. Id string `uri:"id"` // 主键ID
  45. }
  46. type adminMenuResponse struct {
  47. HashID string `json:"hash_id"` // hashID
  48. }
  49. return func(ctx core.Context) {
  50. req := new(adminMenuRequest)
  51. if err := ctx.ShouldBindURI(req); err != nil {
  52. ctx.AbortWithError(core.Error(
  53. http.StatusBadRequest,
  54. code.ParamBindError,
  55. code.Text(code.ParamBindError)).WithError(err),
  56. )
  57. return
  58. }
  59. obj := new(adminMenuResponse)
  60. obj.HashID = req.Id
  61. ctx.HTML("admin_menu", obj)
  62. }
  63. }
  64. func (h *handler) MenuAction() core.HandlerFunc {
  65. type menuActionRequest struct {
  66. Id string `uri:"id"` // 主键ID
  67. }
  68. type menuActionResponse struct {
  69. HashID string `json:"hash_id"` // hashID
  70. }
  71. return func(ctx core.Context) {
  72. req := new(menuActionRequest)
  73. if err := ctx.ShouldBindURI(req); err != nil {
  74. ctx.AbortWithError(core.Error(
  75. http.StatusBadRequest,
  76. code.ParamBindError,
  77. code.Text(code.ParamBindError)).WithError(err),
  78. )
  79. return
  80. }
  81. obj := new(menuActionResponse)
  82. obj.HashID = req.Id
  83. ctx.HTML("menu_action", obj)
  84. }
  85. }
  86. func (h *handler) ModifyInfo() core.HandlerFunc {
  87. return func(ctx core.Context) {
  88. ctx.HTML("admin_modify_info", nil)
  89. }
  90. }
  91. func (h *handler) ModifyPassword() core.HandlerFunc {
  92. return func(ctx core.Context) {
  93. ctx.HTML("admin_modify_password", nil)
  94. }
  95. }