|
|
@ -25,6 +25,8 @@ type (
|
|
|
|
userModel interface {
|
|
|
|
userModel interface {
|
|
|
|
Insert(ctx context.Context, data *User) (sql.Result, error)
|
|
|
|
Insert(ctx context.Context, data *User) (sql.Result, error)
|
|
|
|
FindOne(ctx context.Context, id string) (*User, error)
|
|
|
|
FindOne(ctx context.Context, id string) (*User, error)
|
|
|
|
|
|
|
|
FindOneByEmail(ctx context.Context, email sql.NullString) (*User, error)
|
|
|
|
|
|
|
|
FindOneByPhone(ctx context.Context, phone sql.NullString) (*User, error)
|
|
|
|
FindOneByUsername(ctx context.Context, username string) (*User, error)
|
|
|
|
FindOneByUsername(ctx context.Context, username string) (*User, error)
|
|
|
|
Update(ctx context.Context, data *User) error
|
|
|
|
Update(ctx context.Context, data *User) error
|
|
|
|
Delete(ctx context.Context, id string) error
|
|
|
|
Delete(ctx context.Context, id string) error
|
|
|
@ -41,8 +43,8 @@ type (
|
|
|
|
Updated time.Time `db:"updated"`
|
|
|
|
Updated time.Time `db:"updated"`
|
|
|
|
Username string `db:"username"`
|
|
|
|
Username string `db:"username"`
|
|
|
|
Nickname string `db:"nickname"`
|
|
|
|
Nickname string `db:"nickname"`
|
|
|
|
Email string `db:"email"`
|
|
|
|
Email sql.NullString `db:"email"`
|
|
|
|
Phone string `db:"phone"`
|
|
|
|
Phone sql.NullString `db:"phone"`
|
|
|
|
Icon string `db:"icon"`
|
|
|
|
Icon string `db:"icon"`
|
|
|
|
RealCode string `db:"_real_code"`
|
|
|
|
RealCode string `db:"_real_code"`
|
|
|
|
CheckCode string `db:"_check_code"`
|
|
|
|
CheckCode string `db:"_check_code"`
|
|
|
@ -79,6 +81,34 @@ func (m *defaultUserModel) FindOne(ctx context.Context, id string) (*User, error
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (m *defaultUserModel) FindOneByEmail(ctx context.Context, email sql.NullString) (*User, error) {
|
|
|
|
|
|
|
|
var resp User
|
|
|
|
|
|
|
|
query := fmt.Sprintf("select %s from %s where `email` = ? limit 1", userRows, m.table)
|
|
|
|
|
|
|
|
err := m.conn.QueryRowCtx(ctx, &resp, query, email)
|
|
|
|
|
|
|
|
switch err {
|
|
|
|
|
|
|
|
case nil:
|
|
|
|
|
|
|
|
return &resp, nil
|
|
|
|
|
|
|
|
case sqlx.ErrNotFound:
|
|
|
|
|
|
|
|
return nil, ErrNotFound
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
|
|
return nil, err
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (m *defaultUserModel) FindOneByPhone(ctx context.Context, phone sql.NullString) (*User, error) {
|
|
|
|
|
|
|
|
var resp User
|
|
|
|
|
|
|
|
query := fmt.Sprintf("select %s from %s where `phone` = ? limit 1", userRows, m.table)
|
|
|
|
|
|
|
|
err := m.conn.QueryRowCtx(ctx, &resp, query, phone)
|
|
|
|
|
|
|
|
switch err {
|
|
|
|
|
|
|
|
case nil:
|
|
|
|
|
|
|
|
return &resp, nil
|
|
|
|
|
|
|
|
case sqlx.ErrNotFound:
|
|
|
|
|
|
|
|
return nil, ErrNotFound
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
|
|
return nil, err
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (m *defaultUserModel) FindOneByUsername(ctx context.Context, username string) (*User, error) {
|
|
|
|
func (m *defaultUserModel) FindOneByUsername(ctx context.Context, username string) (*User, error) {
|
|
|
|
var resp User
|
|
|
|
var resp User
|
|
|
|
query := fmt.Sprintf("select %s from %s where `username` = ? limit 1", userRows, m.table)
|
|
|
|
query := fmt.Sprintf("select %s from %s where `username` = ? limit 1", userRows, m.table)
|
|
|
|