add other query

This commit is contained in:
Hoang 2021-11-18 10:30:12 +07:00
parent 2a5e05c3ad
commit 7033a27fc0
3 changed files with 14 additions and 0 deletions

View File

@ -14,6 +14,7 @@ type CommonQuery struct {
RoleID string RoleID string
Status string Status string
Sort interface{} Sort interface{}
Other map[string]interface{}
} }
// AssignKeyword ... // AssignKeyword ...
@ -57,3 +58,13 @@ func (q *CommonQuery) SetDefaultLimit() {
q.Limit = 20 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
}
}
}

View File

@ -41,6 +41,7 @@ type UserAllQuery struct {
RoleID string RoleID string
Status string Status string
Sort interface{} Sort interface{}
Other map[string]interface{} // query fields in other object
} }
// Validate ... // Validate ...

View File

@ -89,6 +89,7 @@ func All(queryParams model.UserAllQuery) (r model.UserAll) {
RoleID: queryParams.RoleID, RoleID: queryParams.RoleID,
Status: queryParams.Status, Status: queryParams.Status,
Sort: queryParams.Sort, Sort: queryParams.Sort,
Other: queryParams.Other,
} }
// Assign condition // Assign condition
@ -96,6 +97,7 @@ func All(queryParams model.UserAllQuery) (r model.UserAll) {
query.AssignKeyword(cond) query.AssignKeyword(cond)
query.AssignRoleID(cond) query.AssignRoleID(cond)
query.AssignStatus(cond) query.AssignStatus(cond)
query.AssignOther(cond)
wg.Add(1) wg.Add(1)
go func() { go func() {