From 29157b25304c6d75d3942664e9d869eab701f1f8 Mon Sep 17 00:00:00 2001 From: Sinh Date: Thu, 17 Nov 2022 10:53:14 +0700 Subject: [PATCH] update query limit --- model/query.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/model/query.go b/model/query.go index fec215a..3d19b8b 100644 --- a/model/query.go +++ b/model/query.go @@ -7,6 +7,8 @@ import ( "go.mongodb.org/mongo-driver/mongo/options" ) +const maxLimit = 500 + // CommonQuery ... type CommonQuery struct { Page int64 @@ -78,9 +80,12 @@ func (q *CommonQuery) GetFindOptionsUsingPage() *options.FindOptions { // SetDefaultLimit ... func (q *CommonQuery) SetDefaultLimit() { - if q.Limit <= 0 || q.Limit > 20 { + if q.Limit <= 0 { q.Limit = 20 } + if q.Limit > maxLimit { + q.Limit = 500 + } } // AssignOther ... -- 2.34.1