update_user_info.go 1.1 KB
package command

import (
	"fmt"
	"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain"
	"reflect"
	"strings"

	"github.com/beego/beego/v2/core/validation"
)

type UpdateUserInfoCommand struct {
	//操作人
	Operator domain.Operator `json:"-"`
	// 头像
	Avatar string `cname:"头像" json:"avatar" valid:"Required"`
	// 用户姓名
	UserName string `cname:"用户姓名" json:"userName" valid:"Required"`
}

func (phoneAuthResetPhoneCommand *UpdateUserInfoCommand) Valid(validation *validation.Validation) {

}

func (phoneAuthResetPhoneCommand *UpdateUserInfoCommand) ValidateCommand() error {
	valid := validation.Validation{}
	b, err := valid.Valid(phoneAuthResetPhoneCommand)
	if err != nil {
		return err
	}
	if !b {
		elem := reflect.TypeOf(phoneAuthResetPhoneCommand).Elem()
		for _, validErr := range valid.Errors {
			field, isExist := elem.FieldByName(validErr.Field)
			if isExist {
				return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
			} else {
				return fmt.Errorf(validErr.Message)
			}
		}
	}
	return nil
}