add count method
This commit is contained in:
parent
14f3f94f98
commit
14ad6b51d8
|
@ -44,6 +44,11 @@ func (s Service) GetAllUsers(query model.UserAllQuery) model.UserAll {
|
|||
return user.All(query)
|
||||
}
|
||||
|
||||
// CountAllUsers ...
|
||||
func (s Service) CountAllUsers(query model.UserCountQuery) int64 {
|
||||
return user.Count(query)
|
||||
}
|
||||
|
||||
// ChangeAllUsersStatus ...
|
||||
func (s Service) ChangeAllUsersStatus(roleID, status string) error {
|
||||
return user.ChangeAllUsersStatus(roleID, status)
|
||||
|
|
|
@ -41,7 +41,13 @@ type UserAllQuery struct {
|
|||
RoleID string
|
||||
Status string
|
||||
Sort interface{}
|
||||
Other map[string]interface{} // query fields in other object
|
||||
Other map[string]interface{} // query fields in other object
|
||||
}
|
||||
|
||||
// UserCountQuery ...
|
||||
type UserCountQuery struct {
|
||||
RoleID string
|
||||
Other map[string]interface{} // query fields in other object
|
||||
}
|
||||
|
||||
// Validate ...
|
||||
|
|
|
@ -143,6 +143,24 @@ func All(queryParams model.UserAllQuery) (r model.UserAll) {
|
|||
return
|
||||
}
|
||||
|
||||
// Count ...
|
||||
func Count(queryParams model.UserCountQuery) int64 {
|
||||
var (
|
||||
ctx = context.Background()
|
||||
cond = bson.M{}
|
||||
)
|
||||
query := model.CommonQuery{
|
||||
RoleID: queryParams.RoleID,
|
||||
Other: queryParams.Other,
|
||||
}
|
||||
|
||||
// Assign condition
|
||||
query.AssignRoleID(cond)
|
||||
query.AssignOther(cond)
|
||||
|
||||
return countByCondition(ctx, cond)
|
||||
}
|
||||
|
||||
func getResponse(ctx context.Context, user model.DBUser) model.User {
|
||||
roleRaw, _ := roleFindByID(ctx, user.RoleID)
|
||||
return model.User{
|
||||
|
|
Loading…
Reference in New Issue