(pageInfo *common.PageInfo)
| 121 | } |
| 122 | |
| 123 | func GetAllUsers(pageInfo *common.PageInfo) (users []*User, total int64, err error) { |
| 124 | // Start transaction |
| 125 | tx := DB.Begin() |
| 126 | if tx.Error != nil { |
| 127 | return nil, 0, tx.Error |
| 128 | } |
| 129 | defer func() { |
| 130 | if r := recover(); r != nil { |
| 131 | tx.Rollback() |
| 132 | } |
| 133 | }() |
| 134 | |
| 135 | // Get total count within transaction |
| 136 | err = tx.Unscoped().Model(&User{}).Count(&total).Error |
| 137 | if err != nil { |
| 138 | tx.Rollback() |
| 139 | return nil, 0, err |
| 140 | } |
| 141 | |
| 142 | // Get paginated users within same transaction |
| 143 | err = tx.Unscoped().Order("id desc").Limit(pageInfo.GetPageSize()).Offset(pageInfo.GetStartIdx()).Omit("password").Find(&users).Error |
| 144 | if err != nil { |
| 145 | tx.Rollback() |
| 146 | return nil, 0, err |
| 147 | } |
| 148 | |
| 149 | // Commit transaction |
| 150 | if err = tx.Commit().Error; err != nil { |
| 151 | return nil, 0, err |
| 152 | } |
| 153 | |
| 154 | return users, total, nil |
| 155 | } |
| 156 | |
| 157 | func SearchUsers(keyword string, group string, startIdx int, num int) ([]*User, int64, error) { |
| 158 | var users []*User |
no test coverage detected