2 Star 1 Fork 2

go-mao/mao

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
user_domain.go 1.39 KB
一键复制 编辑 原始数据 按行查看 历史
haitgo 提交于 2023-12-30 12:04 . 调整hook参数传递方式
package user
import (
"gitee.com/go-mao/mao/frame"
"gitee.com/go-mao/mao/libs/try"
)
type userDomain struct {
*Component
}
func (this *Component) UserDomain() *userDomain {
return &userDomain{this}
}
// 创建用户
func (this *userDomain) Create(username string) *User {
userEntity := this.NewUser()
userEntity.Username = username
if !userEntity.Create() {
try.Throw(frame.CODE_SQL, "用户创建失败")
}
return userEntity
}
// 创建用户
func (this *userDomain) Get(id int64) (*User, bool) {
userEntity := this.NewUser()
exists := userEntity.Match("Id", id).Get()
return userEntity, exists
}
// 创建用户
func (this *userDomain) Update(id int64, username string) {
userEntity, exists := this.Get(id)
if !exists {
try.Throw(frame.CODE_SQL, "找不到该用户")
}
userEntity.Username = username
if !userEntity.Update() {
try.Throw(frame.CODE_SQL, "用户修改失败")
}
}
// 删除用户
func (this *userDomain) Remove(id int64) {
userEntity, exists := this.Get(id)
if !exists {
try.Throw(frame.CODE_SQL, "找不到该用户")
}
if !userEntity.Delete() {
try.Throw(frame.CODE_SQL, "用户删除失败")
}
}
// 用户查询
func (this *userDomain) Find(username string, listPtr any, page, limit int) int64 {
db := this.OrmTable(this.NewUser())
if username != "" {
db.Where("`Username`=?", username)
}
db.Desc("Id")
return this.FindPage(db, listPtr, page, limit)
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/go-mao/mao.git
git@gitee.com:go-mao/mao.git
go-mao
mao
mao
v1.0.25

搜索帮助