user_auth.go 1.3 KB
package domain

import "time"

// 用户认证实体
type UserAuth struct {
	// 用户认证编号
	UserAuthId int64 `json:"userAuthId"`
	// 用户id列表
	Users []int64 `json:"users"`
	// 手机认证
	PhoneAuth *PhoneAuth `json:"phoneAuth"`
	// 创建时间
	CreateAt time.Time `json:"createAt"`
	// 更新时间
	UpdateAt time.Time `json:"updateAt"`
}

type UserAuthRepository interface {
	Save(userAuth *UserAuth) (*UserAuth, error)
	Remove(userAuth *UserAuth) (*UserAuth, error)
	FindOne(queryOptions map[string]interface{}) (*UserAuth, error)
	Find(queryOptions map[string]interface{}) (int64, []*UserAuth, error)
}

func (userAuth *UserAuth) Identify() interface{} {
	if userAuth.UserAuthId == 0 {
		return nil
	}
	return userAuth.UserAuthId
}

func (userAuth *UserAuth) Update(data map[string]interface{}) error {
	if userAuthId, ok := data["userAuthId"]; ok {
		userAuth.UserAuthId = userAuthId.(int64)
	}
	if users, ok := data["users"]; ok {
		userAuth.Users = users.([]int64)
	}
	if phone, ok := data["phone"]; ok {
		userAuth.PhoneAuth.Phone = phone.(string)
	}
	if password, ok := data["password"]; ok {
		userAuth.PhoneAuth.Password = password.(string)
	}
	if createAt, ok := data["createAt"]; ok {
		userAuth.CreateAt = createAt.(time.Time)
	}
	if updateAt, ok := data["updateAt"]; ok {
		userAuth.UpdateAt = updateAt.(time.Time)
	}
	return nil
}