2021-11-20 15:01:50 +08:00
|
|
|
package admin
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
|
|
"github.com/xinliangnote/go-gin-api/internal/code"
|
|
|
|
|
"github.com/xinliangnote/go-gin-api/internal/pkg/core"
|
2021-11-21 13:29:50 +08:00
|
|
|
"github.com/xinliangnote/go-gin-api/internal/repository/mysql"
|
2021-11-21 13:23:27 +08:00
|
|
|
"github.com/xinliangnote/go-gin-api/internal/repository/redis"
|
2021-11-20 15:01:50 +08:00
|
|
|
|
|
|
|
|
"go.uber.org/zap"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type handler struct {
|
2021-11-21 13:23:27 +08:00
|
|
|
db mysql.Repo
|
2021-11-20 15:01:50 +08:00
|
|
|
logger *zap.Logger
|
|
|
|
|
cache redis.Repo
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-21 13:23:27 +08:00
|
|
|
func New(logger *zap.Logger, db mysql.Repo, cache redis.Repo) *handler {
|
2021-11-20 15:01:50 +08:00
|
|
|
return &handler{
|
|
|
|
|
logger: logger,
|
|
|
|
|
cache: cache,
|
|
|
|
|
db: db,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (h *handler) Login() core.HandlerFunc {
|
|
|
|
|
return func(ctx core.Context) {
|
|
|
|
|
ctx.HTML("admin_login", nil)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (h *handler) Add() core.HandlerFunc {
|
|
|
|
|
return func(ctx core.Context) {
|
|
|
|
|
ctx.HTML("admin_add", nil)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (h *handler) List() core.HandlerFunc {
|
|
|
|
|
return func(ctx core.Context) {
|
|
|
|
|
ctx.HTML("admin_list", nil)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (h *handler) Menu() core.HandlerFunc {
|
|
|
|
|
return func(ctx core.Context) {
|
|
|
|
|
ctx.HTML("menu_view", nil)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (h *handler) AdminMenu() core.HandlerFunc {
|
|
|
|
|
type adminMenuRequest struct {
|
|
|
|
|
Id string `uri:"id"` // 主键ID
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type adminMenuResponse struct {
|
|
|
|
|
HashID string `json:"hash_id"` // hashID
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return func(ctx core.Context) {
|
|
|
|
|
req := new(adminMenuRequest)
|
|
|
|
|
if err := ctx.ShouldBindURI(req); err != nil {
|
2021-11-28 13:25:27 +08:00
|
|
|
ctx.AbortWithError(core.Error(
|
2021-11-20 15:01:50 +08:00
|
|
|
http.StatusBadRequest,
|
|
|
|
|
code.ParamBindError,
|
2021-11-28 13:25:27 +08:00
|
|
|
code.Text(code.ParamBindError)).WithError(err),
|
2021-11-20 15:01:50 +08:00
|
|
|
)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
obj := new(adminMenuResponse)
|
|
|
|
|
obj.HashID = req.Id
|
|
|
|
|
|
|
|
|
|
ctx.HTML("admin_menu", obj)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (h *handler) MenuAction() core.HandlerFunc {
|
|
|
|
|
type menuActionRequest struct {
|
|
|
|
|
Id string `uri:"id"` // 主键ID
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type menuActionResponse struct {
|
|
|
|
|
HashID string `json:"hash_id"` // hashID
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return func(ctx core.Context) {
|
|
|
|
|
req := new(menuActionRequest)
|
|
|
|
|
if err := ctx.ShouldBindURI(req); err != nil {
|
2021-11-28 13:25:27 +08:00
|
|
|
ctx.AbortWithError(core.Error(
|
2021-11-20 15:01:50 +08:00
|
|
|
http.StatusBadRequest,
|
|
|
|
|
code.ParamBindError,
|
2021-11-28 13:25:27 +08:00
|
|
|
code.Text(code.ParamBindError)).WithError(err),
|
2021-11-20 15:01:50 +08:00
|
|
|
)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
obj := new(menuActionResponse)
|
|
|
|
|
obj.HashID = req.Id
|
|
|
|
|
|
|
|
|
|
ctx.HTML("menu_action", obj)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (h *handler) ModifyInfo() core.HandlerFunc {
|
|
|
|
|
return func(ctx core.Context) {
|
|
|
|
|
ctx.HTML("admin_modify_info", nil)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (h *handler) ModifyPassword() core.HandlerFunc {
|
|
|
|
|
return func(ctx core.Context) {
|
|
|
|
|
ctx.HTML("admin_modify_password", nil)
|
|
|
|
|
}
|
|
|
|
|
}
|