app-cloudep-member-server/internal/logic/account/update_status_logic.go

50 lines
1.1 KiB
Go

package accountlogic
import (
"context"
ers "code.30cm.net/digimon/library-go/errors"
"app-cloudep-member-server/gen_result/pb/member"
"app-cloudep-member-server/internal/svc"
"github.com/zeromicro/go-zero/core/logx"
)
type UpdateStatusLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewUpdateStatusLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateStatusLogic {
return &UpdateStatusLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
type updateStatusReq struct {
UID string `json:"uid" validate:"required"`
Status int32 `json:"status" validate:"required,oneof=1 2 3 4 5 6"`
}
// UpdateStatus 修改狀態
func (l *UpdateStatusLogic) UpdateStatus(in *member.UpdateStatusReq) (*member.OKResp, error) {
// 驗證資料
if err := l.svcCtx.Validate.ValidateAll(&updateStatusReq{
UID: in.GetUid(),
Status: int32(in.GetStatus()),
}); err != nil {
return nil, ers.InvalidFormat(err.Error())
}
err := l.svcCtx.UserModel.UpdateStatus(l.ctx, in.GetUid(), int32(in.GetStatus()))
if err != nil {
return nil, ers.DBError(err.Error())
}
return &member.OKResp{}, nil
}