diff --git a/model/query.go b/model/query.go index b2af79d..8c01bbb 100644 --- a/model/query.go +++ b/model/query.go @@ -14,6 +14,7 @@ type CommonQuery struct { RoleID string Status string Sort interface{} + Other map[string]interface{} } // AssignKeyword ... @@ -57,3 +58,13 @@ func (q *CommonQuery) SetDefaultLimit() { q.Limit = 20 } } + +// AssignOther ... +func (q *CommonQuery) AssignOther(cond bson.M) { + // Query fields in other object + if len(q.Other) > 0 { + for key, value := range q.Other { + cond["other."+key] = value + } + } +} diff --git a/model/user_request.go b/model/user_request.go index 3c7f3f6..05f36d8 100644 --- a/model/user_request.go +++ b/model/user_request.go @@ -41,6 +41,7 @@ type UserAllQuery struct { RoleID string Status string Sort interface{} + Other map[string]interface{} // query fields in other object } // Validate ... diff --git a/user/handle.go b/user/handle.go index 3d62dca..8fec3c8 100644 --- a/user/handle.go +++ b/user/handle.go @@ -89,6 +89,7 @@ func All(queryParams model.UserAllQuery) (r model.UserAll) { RoleID: queryParams.RoleID, Status: queryParams.Status, Sort: queryParams.Sort, + Other: queryParams.Other, } // Assign condition @@ -96,6 +97,7 @@ func All(queryParams model.UserAllQuery) (r model.UserAll) { query.AssignKeyword(cond) query.AssignRoleID(cond) query.AssignStatus(cond) + query.AssignOther(cond) wg.Add(1) go func() {