DriveLinked/pkg/model/user.go

40 lines
916 B
Go

package model
import (
"drive-linked/pkg/dao"
"fmt"
"github.com/jmoiron/sqlx"
"strings"
)
type User struct {
ID int64 `json:"id,string"`
Name string `json:"name"`
Nickname string `json:"nickname"`
Email string `json:"email"`
Password string `json:"-"`
Status int32 `json:"status"`
Avatar string `json:"avatar"`
Roles string `json:"roles"`
}
func (user *User) GetProfileWithConditions(conditions *map[string]interface{}) error {
// 支持多条件查询
//TODO:分离多条件查询部分,有利于代码复用
var where []string
var values []interface{}
for k, v := range *conditions {
values = append(values, v)
where = append(where, fmt.Sprintf(`"%s" = %s`, k, "?"))
}
exec := sqlx.Rebind(sqlx.QUESTION, "SELECT * FROM users WHERE "+strings.Join(where, "AND")+" LIMIT 1")
err := dao.DB.Get(user, exec, values...)
if err != nil {
return err
}
return nil
}