You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
586 B
36 lines
586 B
6 years ago
|
package service
|
||
|
|
||
|
import (
|
||
|
"github.com/astaxie/beego/orm"
|
||
|
"beeblog/models"
|
||
|
)
|
||
|
|
||
|
type UserService struct {
|
||
|
}
|
||
|
|
||
|
func FindByUserName(username string) (*models.User, error) {
|
||
|
o := orm.NewOrm()
|
||
|
qs := o.QueryTable(&models.User{})
|
||
|
var users []*models.User
|
||
|
_, err := qs.Filter("UserName", username).All(&users)
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
if len(users) != 0 {
|
||
|
return users[0], nil
|
||
|
}
|
||
|
return nil, nil
|
||
|
}
|
||
|
|
||
|
func SaveUser(user *models.User) error {
|
||
|
o := orm.NewOrm()
|
||
|
id, eror := o.Insert(user)
|
||
|
if eror != nil {
|
||
|
return eror
|
||
|
} else {
|
||
|
user.Id = id
|
||
|
o.Commit()
|
||
|
}
|
||
|
return nil
|
||
|
}
|