@@ -76,7 +76,7 @@ func (la *ListQuotaAction) doHost(ctx context.Context, req *proto.ListProjectQuo
7676 cond := operator .NewBranchCondition (operator .And , conds ... )
7777
7878 quotas , _ , errQ := la .model .ListProjectQuotas (la .ctx , cond , & page.Pagination {All : true })
79- if err != nil {
79+ if errQ != nil {
8080 return pquota , errorx .NewDBErr (errQ .Error ())
8181 }
8282
@@ -178,12 +178,12 @@ func (la *ListQuotaAction) doFed(req *proto.ListProjectQuotasRequest,
178178
179179 cond := operator .NewBranchCondition (operator .And , conds ... )
180180
181- Quotas , _ , err := la .model .ListProjectQuotas (la .ctx , cond , & page.Pagination {All : true })
181+ quotas , _ , err := la .model .ListProjectQuotas (la .ctx , cond , & page.Pagination {All : true })
182182 if err != nil {
183183 return pquota , errorx .NewDBErr (err .Error ())
184184 }
185185
186- for _ , q := range Quotas {
186+ for _ , q := range quotas {
187187 tmp := q
188188 getQuotaUsage (& tmp )
189189 pquota = append (pquota , quota .TransStore2ProtoQuota (& tmp ))
@@ -252,14 +252,14 @@ func (la *ListQuotaV2Action) Do(ctx context.Context,
252252 la .req = req
253253 la .resp = resp
254254
255- var PQ []* proto.ProjectQuota
255+ var pqs []* proto.ProjectQuota
256256
257257 err := la .validate ()
258258 if err != nil {
259259 return err
260260 }
261261
262- pQuotas , count , err := la .getProjectQuotas (ctx , req , PQ )
262+ pQuotas , count , err := la .getProjectQuotas (ctx , req , pqs )
263263 if err != nil {
264264 return err
265265 }
@@ -287,6 +287,14 @@ func (la *ListQuotaV2Action) validate() error {
287287 return errorx .NewParamErr ("quota type is required" )
288288 }
289289
290+ if la .req .Page <= 0 {
291+ la .req .Page = 1
292+ }
293+
294+ if la .req .Limit <= 0 {
295+ la .req .Limit = page .DefaultPageLimit
296+ }
297+
290298 proj , err := la .model .GetProject (context .TODO (), la .req .GetProjectIDOrCode ())
291299 if err != nil {
292300 logging .Error ("get project from db failed, err: %s" , err .Error ())
@@ -344,7 +352,7 @@ func (la *ListQuotaV2Action) getProjectQuotas(ctx context.Context, req *proto.Li
344352
345353 cond := operator .NewBranchCondition (operator .And , conds ... )
346354
347- quotas , total , err := la .model .ListProjectQuotas (ctx , cond , la .paginationOpt ())
355+ quotas , total , err := la .model .ListProjectQuotas (ctx , cond , la .getPaginationOpt ())
348356 if err != nil {
349357 return nil , 0 , errorx .NewDBErr (fmt .Sprintf ("ListProjectQuotas failed," +
350358 " req:[%s], err:[%s]" , req .String (), err .Error ()))
@@ -358,31 +366,13 @@ func (la *ListQuotaV2Action) getProjectQuotas(ctx context.Context, req *proto.Li
358366 return pQuotas , total , nil
359367}
360368
361- const (
362- listProjectQuotasPageLimit = 100
363- )
364-
365- func (la * ListQuotaV2Action ) paginationOpt () * page.Pagination {
366- pagination := & page.Pagination {All : true }
367- if la .req .Page == 0 && la .req .Limit == 0 {
368- return pagination
369- }
370-
371- pagination .All = false
369+ func (la * ListQuotaV2Action ) getPaginationOpt () * page.Pagination {
370+ pagination := & page.Pagination {All : false }
372371 pagination .Sort = map [string ]int {"createtime" : - 1 }
373372
374- if la .req .Page > 0 {
375- offset := int64 (la .req .Page ) - 1
376- pagination .Offset = offset
377- } else {
378- pagination .Offset = 0
379- }
380-
381- if la .req .Limit > 0 {
382- pagination .Limit = int64 (la .req .Limit )
383- } else {
384- pagination .Limit = listProjectQuotasPageLimit
385- }
373+ offset := int64 (la .req .Page - 1 )
374+ pagination .Offset = offset
375+ pagination .Limit = int64 (la .req .Limit )
386376
387377 return pagination
388378}
0 commit comments