add other query
This commit is contained in:
		
							parent
							
								
									2a5e05c3ad
								
							
						
					
					
						commit
						7033a27fc0
					
				|  | @ -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 | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
|  |  | |||
|  | @ -41,6 +41,7 @@ type UserAllQuery struct { | |||
| 	RoleID  string | ||||
| 	Status  string | ||||
| 	Sort    interface{} | ||||
| 	Other   map[string]interface{}  // query fields in other object
 | ||||
| } | ||||
| 
 | ||||
| // Validate ...
 | ||||
|  |  | |||
|  | @ -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() { | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue