forked from free-lancers/electricity_bill_calc_service
enhance(repository):改进查询条件的生成方式。
This commit is contained in:
@@ -4,6 +4,8 @@ import (
|
||||
"electricity_bill_calc/cache"
|
||||
"electricity_bill_calc/global"
|
||||
"electricity_bill_calc/model"
|
||||
|
||||
"xorm.io/builder"
|
||||
)
|
||||
|
||||
type _UserRepository struct{}
|
||||
@@ -16,7 +18,7 @@ func (_UserRepository) FindUserByUsername(username string) (*model.User, error)
|
||||
return cachedUser, nil
|
||||
}
|
||||
user := new(model.User)
|
||||
has, err := global.DBConn.Where("username=?", username).Get(user)
|
||||
has, err := global.DBConn.Where(builder.Eq{"username": username}).Get(user)
|
||||
if has {
|
||||
cache.CacheData(user, "user", username)
|
||||
}
|
||||
@@ -29,7 +31,7 @@ func (_UserRepository) RetreiveUserDetail(uid string) (*model.UserDetail, error)
|
||||
return cachedUser, nil
|
||||
}
|
||||
user := new(model.UserDetail)
|
||||
has, err := global.DBConn.Where("id=?", uid).Get(user)
|
||||
has, err := global.DBConn.ID(uid).Get(user)
|
||||
if has {
|
||||
cache.CacheData(user, "user_detail", uid)
|
||||
}
|
||||
|
Reference in New Issue
Block a user