MCPcopy Create free account
hub / github.com/aiprodcoder/MIXAPI / GetAllUsers

Function GetAllUsers

model/user.go:123–155  ·  view source on GitHub ↗
(pageInfo *common.PageInfo)

Source from the content-addressed store, hash-verified

121}
122
123func 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
157func SearchUsers(keyword string, group string, startIdx int, num int) ([]*User, int64, error) {
158 var users []*User

Callers 1

GetAllUsersFunction · 0.92

Calls 2

GetPageSizeMethod · 0.80
GetStartIdxMethod · 0.80

Tested by

no test coverage detected