electricity_bill_calc_service/repository/user.go

53 lines
1.3 KiB
Go

package repository
import (
"electricity_bill_calc/cache"
"electricity_bill_calc/global"
"electricity_bill_calc/model"
"xorm.io/builder"
)
type _UserRepository struct{}
var UserRepo _UserRepository
func (_UserRepository) FindUserByUsername(username string) (*model.User, error) {
cachedUser, _ := cache.RetreiveData[model.User]("user", username)
if cachedUser != nil {
return cachedUser, nil
}
user := new(model.User)
has, err := global.DBConn.Where(builder.Eq{"username": username}).Get(user)
if has {
cache.CacheData(user, "user", username)
}
return _postProcessSingle(user, has, err)
}
func (_UserRepository) RetreiveUserDetail(uid string) (*model.UserDetail, error) {
cachedUser, _ := cache.RetreiveData[model.UserDetail]("user", uid)
if cachedUser != nil {
return cachedUser, nil
}
user := new(model.UserDetail)
has, err := global.DBConn.ID(uid).Get(user)
if has {
cache.CacheData(user, "user_detail", uid)
}
return _postProcessSingle(user, has, err)
}
func (_UserRepository) FindUserByID(uid string) (*model.User, error) {
cachedUser, _ := cache.RetreiveData[model.User]("user", uid)
if cachedUser != nil {
return cachedUser, nil
}
user := new(model.User)
has, err := global.DBConn.ID(uid).Get(user)
if has {
cache.CacheData(user, "user", uid)
}
return _postProcessSingle(user, has, err)
}