update
This commit is contained in:
@@ -97,6 +97,25 @@ func (h *Handler) Delete(c *gin.Context) {
|
||||
response.OK(c, nil)
|
||||
}
|
||||
|
||||
// UpdateStatus 更新小程序状态(0 禁用、1 启用)。
|
||||
func (h *Handler) UpdateStatus(c *gin.Context) {
|
||||
id, ok := parseID(c)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
var req miniappsvc.StatusReq
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
c.Error(errors.ErrBadRequest)
|
||||
return
|
||||
}
|
||||
m, err := h.svc.UpdateStatus(c.Request.Context(), id, req.Status)
|
||||
if err != nil {
|
||||
c.Error(err)
|
||||
return
|
||||
}
|
||||
response.OK(c, m)
|
||||
}
|
||||
|
||||
// parseID 从路径参数解析并校验 uint64 主键。
|
||||
func parseID(c *gin.Context) (uint64, bool) {
|
||||
id, err := strconv.ParseUint(c.Param("id"), 10, 64)
|
||||
@@ -117,5 +136,6 @@ func Register(g *gin.RouterGroup, h *Handler) {
|
||||
rg.GET("/:id", middleware.RequirePerm(middleware.PermMiniView), h.Get)
|
||||
rg.GET("", middleware.RequirePerm(middleware.PermMiniView), h.List)
|
||||
rg.DELETE("/:id", middleware.RequirePerm(middleware.PermMiniManage), h.Delete)
|
||||
rg.PUT("/:id/status", middleware.RequirePerm(middleware.PermMiniManage), h.UpdateStatus)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
"portal-mini-go/internal/model"
|
||||
"portal-mini-go/internal/pkg/errors"
|
||||
"portal-mini-go/internal/pkg/response"
|
||||
"portal-mini-go/internal/pkg/types"
|
||||
app1svc "portal-mini-go/internal/service/miniapp/app1"
|
||||
)
|
||||
|
||||
@@ -110,12 +111,12 @@ func (h *Handler) ListUsers(c *gin.Context) {
|
||||
|
||||
// ProfileView 当前用户自身的资料视图(含自身 openid/unionid)。
|
||||
type ProfileView struct {
|
||||
ID uint64 `json:"id"`
|
||||
OpenID string `json:"openid"`
|
||||
UnionID string `json:"union_id"`
|
||||
Nickname string `json:"nickname"`
|
||||
Avatar string `json:"avatar"`
|
||||
CreatedAt int64 `json:"created_at"`
|
||||
ID uint64 `json:"id"`
|
||||
OpenID string `json:"openid"`
|
||||
UnionID string `json:"union_id"`
|
||||
Nickname string `json:"nickname"`
|
||||
Avatar string `json:"avatar"`
|
||||
CreatedAt types.Time `json:"created_at"`
|
||||
}
|
||||
|
||||
// PublicUserView 对外的用户公开视图,剔除 openid/unionid 等敏感字段。
|
||||
@@ -132,7 +133,7 @@ func toProfileView(u *model.User) ProfileView {
|
||||
UnionID: u.UnionID,
|
||||
Nickname: u.Nickname,
|
||||
Avatar: u.Avatar,
|
||||
CreatedAt: u.CreatedAt.Unix(),
|
||||
CreatedAt: u.CreatedAt,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user