From 3c4eab8977d49d267936de48878ca596d3445b5a Mon Sep 17 00:00:00 2001 From: Hoang Date: Sat, 20 Nov 2021 22:00:00 +0700 Subject: [PATCH] update UserAllQuery --- model/query.go | 11 +++++++++++ model/user_request.go | 1 + user/handle.go | 2 ++ 3 files changed, 14 insertions(+) diff --git a/model/query.go b/model/query.go index 8c01bbb..84413f3 100644 --- a/model/query.go +++ b/model/query.go @@ -13,10 +13,21 @@ type CommonQuery struct { Keyword string RoleID string Status string + Deleted string Sort interface{} Other map[string]interface{} } +// AssignDeleted ... +func (q *CommonQuery) AssignDeleted(cond bson.M) { + if q.Deleted == "true" { + cond["deleted"] = true + } + if q.Deleted == "false" { + cond["deleted"] = false + } +} + // AssignKeyword ... func (q *CommonQuery) AssignKeyword(cond bson.M) { if q.Keyword != "" { diff --git a/model/user_request.go b/model/user_request.go index 42678b2..9e3f2a3 100644 --- a/model/user_request.go +++ b/model/user_request.go @@ -40,6 +40,7 @@ type UserAllQuery struct { Keyword string RoleID string Status string + Deleted string // true or false Sort interface{} Other map[string]interface{} // query fields in other object } diff --git a/user/handle.go b/user/handle.go index b011edf..dae3dc9 100644 --- a/user/handle.go +++ b/user/handle.go @@ -112,6 +112,7 @@ func All(queryParams model.UserAllQuery) (r model.UserAll) { Status: queryParams.Status, Sort: queryParams.Sort, Other: queryParams.Other, + Deleted: queryParams.Deleted, } // Assign condition @@ -119,6 +120,7 @@ func All(queryParams model.UserAllQuery) (r model.UserAll) { query.AssignKeyword(cond) query.AssignRoleID(cond) query.AssignStatus(cond) + query.AssignDeleted(cond) query.AssignOther(cond) wg.Add(1)