Skip to content

Commit

Permalink
Fix/usermodel (#38)
Browse files Browse the repository at this point in the history
* fix(model):role delete add where condition
  • Loading branch information
chanoe authored Feb 18, 2022
1 parent e9889c6 commit fea9464
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 6 deletions.
3 changes: 2 additions & 1 deletion model/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type Page struct {
IsDescending bool `json:"is_descending"` // false:ascending;true:descending
}

func FormatPage(db *gorm.DB, page *Page) {
func FormatPage(db *gorm.DB, page *Page) *gorm.DB {
if page.PageNum <= 0 {
page.PageNum = 1
}
Expand All @@ -47,4 +47,5 @@ func FormatPage(db *gorm.DB, page *Page) {
db = db.Order(page.OrderBy)
}
}
return db
}
6 changes: 3 additions & 3 deletions model/roles.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func (dao *Role) List(db *gorm.DB, where map[string]interface{}, page *Page, key
db = db.Where("name like ? or description like ?", "%"+keywords+"%", "%"+keywords+"%")
}
if page != nil {
FormatPage(db, page)
db = FormatPage(db, page)
}
err = db.Find(&roles).Count(&total).Error
return
Expand All @@ -76,8 +76,8 @@ func (dao *Role) Update(db *gorm.DB, where map[string]interface{}, updates map[s
return result.RowsAffected, result.Error
}

func (dao *Role) Delete(db *gorm.DB) (affected int64, err error) {
result := db.Delete(dao)
func (dao *Role) Delete(db *gorm.DB, where map[string]interface{}) (affected int64, err error) {
result := db.Delete(dao, where)
return result.RowsAffected, result.Error
}

Expand Down
2 changes: 1 addition & 1 deletion model/tenant.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func (o *Tenant) List(db *gorm.DB, where map[string]interface{}, page *Page, key
db = db.Where("concat (id, title, remark) like ?", "%"+keywords+"%")
}
if page != nil {
FormatPage(db, page)
db = FormatPage(db, page)
}
err = db.Find(&tenants).Count(&total).Error
return
Expand Down
2 changes: 1 addition & 1 deletion model/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func (u *User) QueryByCondition(db *gorm.DB, condition map[string]interface{}, p
}
db = db.Where(condition).Count(&total)
if page != nil {
FormatPage(db, page)
db = FormatPage(db, page)
}
err = db.Find(&users).Error
if errors.Is(err, gorm.ErrRecordNotFound) {
Expand Down

0 comments on commit fea9464

Please sign in to comment.