feat: fix param post status convert error

pull/25/head v1.0.2
1379 2 years ago committed by 1379Monitor
parent 1f14361092
commit f1c1addacb

@ -325,6 +325,19 @@ func (c PostStatus) Ptr() *PostStatus {
return &c
}
func PostStatusFromString(str string) (PostStatus, error) {
if str == "PUBLISHED" {
return PostStatusPublished, nil
} else if str == "DRAFT" {
return PostStatusDraft, nil
} else if str == "RECYCLE" {
return PostStatusRecycle, nil
} else if str == "INTIMATE" {
return PostStatusIntimate, nil
}
return PostStatusDraft, xerr.BadParam.New("").WithMsg("unknown PostStatus")
}
type CommentStatus int32
const (

@ -66,11 +66,14 @@ func (m *MenuHandler) ListMenusAsTreeByTeam(ctx *gin.Context) (interface{}, erro
if len(sort.Fields) == 0 {
sort.Fields = append(sort.Fields, "priority,asc")
}
team, err := util.MustGetQueryString(ctx, "team")
if err != nil {
return nil, err
team, _ := util.MustGetQueryString(ctx, "team")
if team == "" {
menus, err := m.MenuService.ListAsTree(ctx, &sort)
if err != nil {
return nil, err
}
return menus, nil
}
menus, err := m.MenuService.ListAsTreeByTeam(ctx, team, &sort)
if err != nil {
return nil, err

@ -203,11 +203,15 @@ func (p *PostHandler) UpdatePostStatus(ctx *gin.Context) (interface{}, error) {
if err != nil {
return nil, xerr.WithStatus(err, xerr.StatusBadRequest).WithMsg("Parameter error")
}
status, err := util.ParamInt32(ctx, "status")
statusStr, err := util.ParamString(ctx, "status")
if err != nil {
return nil, xerr.WithStatus(err, xerr.StatusBadRequest).WithMsg("Parameter error")
}
status, err := consts.PostStatusFromString(statusStr)
if err != nil {
return nil, xerr.WithStatus(err, xerr.StatusBadRequest).WithMsg("Parameter error")
}
if status < int32(consts.PostStatusPublished) || status > int32(consts.PostStatusIntimate) {
if int32(status) < int32(consts.PostStatusPublished) || int32(status) > int32(consts.PostStatusIntimate) {
return nil, xerr.WithStatus(nil, xerr.StatusBadRequest).WithMsg("status error")
}
post, err := p.PostService.UpdateStatus(ctx, int32(postID), consts.PostStatus(status))
@ -218,11 +222,15 @@ func (p *PostHandler) UpdatePostStatus(ctx *gin.Context) (interface{}, error) {
}
func (p *PostHandler) UpdatePostStatusBatch(ctx *gin.Context) (interface{}, error) {
status, err := util.ParamInt32(ctx, "status")
statusStr, err := util.ParamString(ctx, "status")
if err != nil {
return nil, err
}
status, err := consts.PostStatusFromString(statusStr)
if err != nil {
return nil, err
}
if status < int32(consts.PostStatusPublished) || status > int32(consts.PostStatusIntimate) {
if int32(status) < int32(consts.PostStatusPublished) || int32(status) > int32(consts.PostStatusIntimate) {
return nil, xerr.WithStatus(nil, xerr.StatusBadRequest).WithMsg("status error")
}
ids := make([]int32, 0)

Loading…
Cancel
Save