mirror of
https://github.com/xinliangnote/go-gin-api.git
synced 2024-04-21 12:31:46 +00:00
- 将 middleware 命名为 interceptor - 将 deploy 命名为 deployments - 移除 pkg/errno - 使用 proposal 目录 - 优化代码
71 lines
1.7 KiB
Go
Executable File
71 lines
1.7 KiB
Go
Executable File
package admin
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/xinliangnote/go-gin-api/configs"
|
|
"github.com/xinliangnote/go-gin-api/internal/code"
|
|
"github.com/xinliangnote/go-gin-api/internal/pkg/core"
|
|
"github.com/xinliangnote/go-gin-api/internal/pkg/password"
|
|
"github.com/xinliangnote/go-gin-api/internal/repository/redis"
|
|
)
|
|
|
|
type offlineRequest struct {
|
|
Id string `form:"id"` // 主键ID
|
|
}
|
|
|
|
type offlineResponse struct {
|
|
Id int32 `json:"id"` // 主键ID
|
|
}
|
|
|
|
// Offline 下线管理员
|
|
// @Summary 下线管理员
|
|
// @Description 下线管理员
|
|
// @Tags API.admin
|
|
// @Accept application/x-www-form-urlencoded
|
|
// @Produce json
|
|
// @Param id formData string true "Hashid"
|
|
// @Success 200 {object} offlineResponse
|
|
// @Failure 400 {object} code.Failure
|
|
// @Router /api/admin/offline [patch]
|
|
// @Security LoginToken
|
|
func (h *handler) Offline() core.HandlerFunc {
|
|
return func(c core.Context) {
|
|
req := new(offlineRequest)
|
|
res := new(offlineResponse)
|
|
if err := c.ShouldBindForm(req); err != nil {
|
|
c.AbortWithError(core.Error(
|
|
http.StatusBadRequest,
|
|
code.ParamBindError,
|
|
code.Text(code.ParamBindError)).WithError(err),
|
|
)
|
|
return
|
|
}
|
|
|
|
ids, err := h.hashids.HashidsDecode(req.Id)
|
|
if err != nil {
|
|
c.AbortWithError(core.Error(
|
|
http.StatusBadRequest,
|
|
code.HashIdsDecodeError,
|
|
code.Text(code.HashIdsDecodeError)).WithError(err),
|
|
)
|
|
return
|
|
}
|
|
|
|
id := int32(ids[0])
|
|
|
|
b := h.cache.Del(configs.RedisKeyPrefixLoginUser+password.GenerateLoginToken(id), redis.WithTrace(c.Trace()))
|
|
if !b {
|
|
c.AbortWithError(core.Error(
|
|
http.StatusBadRequest,
|
|
code.AdminOfflineError,
|
|
code.Text(code.AdminOfflineError)),
|
|
)
|
|
return
|
|
}
|
|
|
|
res.Id = id
|
|
c.Payload(res)
|
|
}
|
|
}
|