57 lines
1.3 KiB
Go
57 lines
1.3 KiB
Go
package logic
|
|
|
|
import (
|
|
"context"
|
|
"strconv"
|
|
|
|
"lone-services/pkg/modelbase"
|
|
"lone-services/pkg/utils"
|
|
"lone-services/pkg/validate"
|
|
user "lone-services/rpc/user/pb"
|
|
"lone-services/services/user/internal/model"
|
|
"lone-services/services/user/internal/svc"
|
|
"lone-services/services/user/validator"
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
)
|
|
|
|
type UserStatusLogic struct {
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
logx.Logger
|
|
}
|
|
|
|
func NewUserStatusLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserStatusLogic {
|
|
return &UserStatusLogic{
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
Logger: logx.WithContext(ctx),
|
|
}
|
|
}
|
|
|
|
func (l *UserStatusLogic) UserStatus(in *user.UserStatusReq) (*user.Response, error) {
|
|
var v validator.UserStatusValidator
|
|
if msg := validate.ValidateFromProto(in, &v); msg != utils.StringEmpty {
|
|
return outResponse(utils.ErrorParams, msg), nil
|
|
}
|
|
|
|
adminInfo := utils.GetUserFromCtx(l.ctx)
|
|
if adminInfo.ID < utils.NumberOne {
|
|
return failResponse(utils.ErrorNoLoginInfo), nil
|
|
}
|
|
|
|
_, err := model.UserModel{}.Init().Edit(modelbase.Params{
|
|
Eq: map[string]string{
|
|
"id": strconv.FormatInt(v.Id, utils.NumberTen),
|
|
},
|
|
}, map[string]interface{}{
|
|
"status": v.Status,
|
|
})
|
|
if err != nil {
|
|
l.Errorf("user status: %v", err)
|
|
return failResponse(utils.Fail), nil
|
|
}
|
|
|
|
return okResponse(nil), nil
|
|
}
|