From 46a498e7c6a0428f1075fc4571c16ac26dd77f2d Mon Sep 17 00:00:00 2001 From: Rogee Date: Sat, 21 Dec 2024 00:27:37 +0800 Subject: [PATCH] feat: fix issues --- templates/project/app/requests/pagination.go.tpl | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/templates/project/app/requests/pagination.go.tpl b/templates/project/app/requests/pagination.go.tpl index 910457c..31bb855 100644 --- a/templates/project/app/requests/pagination.go.tpl +++ b/templates/project/app/requests/pagination.go.tpl @@ -1,5 +1,7 @@ package requests +import "github.com/samber/lo" + type Pager struct { Pagination `json:",inline"` Total int64 `json:"total"` @@ -7,25 +9,22 @@ type Pager struct { } type Pagination struct { - Page int `json:"page" form:"page"` - Limit int `json:"limit" form:"limit"` + Page int `json:"page" form:"page" query:"page"` + Limit int `json:"limit" form:"limit" query:"limit"` } -func (filter *PageQueryFilter) Offset() int { +func (filter *Pagination) Offset() int { return (filter.Page - 1) * filter.Limit } -func (filter *PageQueryFilter) Format() *PageQueryFilter { +func (filter *Pagination) Format() *Pagination { if filter.Page <= 0 { filter.Page = 1 } - if filter.Limit <= 0 { + if !lo.Contains([]int{10, 20, 50, 100}, filter.Limit) { filter.Limit = 10 } - if filter.Limit > 50 { - filter.Limit = 50 - } return filter }