feat: add user register

This commit is contained in:
2025-12-17 20:43:08 +08:00
parent f86898ae5f
commit f0449bab25
9 changed files with 216 additions and 42 deletions

View File

@@ -10,6 +10,7 @@ type User struct {
BaseModel
Username string `gorm:"column:username" json:"username"`
Phone string `gorm:"column:phone" json:"phone"`
Email string `gorm:"column:email" json:"email"`
Password string `gorm:"column:password" json:"password"`
WechatOpenID string `gorm:"column:wechat_open_id" json:"wechat_open_id"`
WechatUnionID string `gorm:"column:wechat_union_id" json:"wechat_union_id"`
@@ -51,3 +52,14 @@ func (dao *UserDao) GetByID(tx *gorm.DB, id int64) (*User, error) {
}
return &user, nil
}
func (dao *UserDao) GetByEmail(tx *gorm.DB, email string) (*User, error) {
var user User
if err := tx.Where("email = ?", email).First(&user).Error; err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
return nil, nil
}
return nil, err
}
return &user, nil
}