add count method

This commit is contained in:
Hoang 2021-11-19 11:00:18 +07:00
parent 14f3f94f98
commit 14ad6b51d8
3 changed files with 30 additions and 1 deletions

View File

@ -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)

View File

@ -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 ...

View File

@ -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{