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)
|
return user.All(query)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CountAllUsers ...
|
||||||
|
func (s Service) CountAllUsers(query model.UserCountQuery) int64 {
|
||||||
|
return user.Count(query)
|
||||||
|
}
|
||||||
|
|
||||||
// ChangeAllUsersStatus ...
|
// ChangeAllUsersStatus ...
|
||||||
func (s Service) ChangeAllUsersStatus(roleID, status string) error {
|
func (s Service) ChangeAllUsersStatus(roleID, status string) error {
|
||||||
return user.ChangeAllUsersStatus(roleID, status)
|
return user.ChangeAllUsersStatus(roleID, status)
|
||||||
|
|
|
@ -44,6 +44,12 @@ type UserAllQuery struct {
|
||||||
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 ...
|
// Validate ...
|
||||||
func (co UserCreateOptions) Validate() error {
|
func (co UserCreateOptions) Validate() error {
|
||||||
// Name
|
// Name
|
||||||
|
|
|
@ -143,6 +143,24 @@ func All(queryParams model.UserAllQuery) (r model.UserAll) {
|
||||||
return
|
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 {
|
func getResponse(ctx context.Context, user model.DBUser) model.User {
|
||||||
roleRaw, _ := roleFindByID(ctx, user.RoleID)
|
roleRaw, _ := roleFindByID(ctx, user.RoleID)
|
||||||
return model.User{
|
return model.User{
|
||||||
|
|
Loading…
Reference in New Issue