Skip to content

Commit

Permalink
feat: 优化分页
Browse files Browse the repository at this point in the history
  • Loading branch information
devhaozi committed Nov 5, 2023
1 parent 01620eb commit 0a3573b
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 18 deletions.
18 changes: 9 additions & 9 deletions app/http/controllers/cert_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,15 +125,15 @@ func (r *CertController) Algorithms(ctx http.Context) http.Response {
// @Failure 500 {object} ErrorResponse "系统内部错误"
// @Router /panel/cert/users [get]
func (r *CertController) UserList(ctx http.Context) http.Response {
var updateProfileRequest commonrequests.Paginate
sanitize := Sanitize(ctx, &updateProfileRequest)
var paginateRequest commonrequests.Paginate
sanitize := Sanitize(ctx, &paginateRequest)
if sanitize != nil {
return sanitize
}

var users []models.CertUser
var total int64
err := facades.Orm().Query().Paginate(updateProfileRequest.Page, updateProfileRequest.Limit, &users, &total)
err := facades.Orm().Query().Paginate(paginateRequest.Page, paginateRequest.Limit, &users, &total)
if err != nil {
facades.Log().Request(ctx.Request()).Tags("面板", "证书管理").With(map[string]any{
"error": err.Error(),
Expand Down Expand Up @@ -215,15 +215,15 @@ func (r *CertController) UserDelete(ctx http.Context) http.Response {
// @Failure 500 {object} ErrorResponse "系统内部错误"
// @Router /panel/cert/dns [get]
func (r *CertController) DNSList(ctx http.Context) http.Response {
var updateProfileRequest commonrequests.Paginate
sanitize := Sanitize(ctx, &updateProfileRequest)
var paginateRequest commonrequests.Paginate
sanitize := Sanitize(ctx, &paginateRequest)
if sanitize != nil {
return sanitize
}

var dns []models.CertDNS
var total int64
err := facades.Orm().Query().Paginate(updateProfileRequest.Page, updateProfileRequest.Limit, &dns, &total)
err := facades.Orm().Query().Paginate(paginateRequest.Page, paginateRequest.Limit, &dns, &total)
if err != nil {
facades.Log().Request(ctx.Request()).Tags("面板", "证书管理").With(map[string]any{
"error": err.Error(),
Expand Down Expand Up @@ -305,15 +305,15 @@ func (r *CertController) DNSDelete(ctx http.Context) http.Response {
// @Failure 500 {object} ErrorResponse "系统内部错误"
// @Router /panel/cert/certs [get]
func (r *CertController) CertList(ctx http.Context) http.Response {
var updateProfileRequest commonrequests.Paginate
sanitize := Sanitize(ctx, &updateProfileRequest)
var paginateRequest commonrequests.Paginate
sanitize := Sanitize(ctx, &paginateRequest)
if sanitize != nil {
return sanitize
}

var certs []models.Cert
var total int64
err := facades.Orm().Query().Paginate(updateProfileRequest.Page, updateProfileRequest.Limit, &certs, &total)
err := facades.Orm().Query().Paginate(paginateRequest.Page, paginateRequest.Limit, &certs, &total)
if err != nil {
facades.Log().Request(ctx.Request()).Tags("面板", "证书管理").With(map[string]any{
"error": err.Error(),
Expand Down
5 changes: 0 additions & 5 deletions app/http/requests/cert/cert_add.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,5 @@ func (r *CertAdd) Attributes(ctx http.Context) map[string]string {
}

func (r *CertAdd) PrepareForValidation(ctx http.Context, data validation.Data) error {
err := data.Set("user_id", uint(ctx.Request().InputInt("user_id")))
if err != nil {
return err
}

return nil
}
3 changes: 0 additions & 3 deletions app/http/requests/common/paginate.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,5 @@ func (r *Paginate) Attributes(ctx http.Context) map[string]string {
}

func (r *Paginate) PrepareForValidation(ctx http.Context, data validation.Data) error {
_ = data.Set("page", ctx.Request().QueryInt("page"))
_ = data.Set("limit", ctx.Request().QueryInt("limit"))

return nil
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
github.com/go-acme/lego/v4 v4.14.2
github.com/gookit/color v1.5.4
github.com/goravel/fiber v1.1.10
github.com/goravel/framework v1.13.1-0.20231104153423-7bfd9573b12d
github.com/goravel/framework v1.13.1-0.20231105145249-62c723ac8fd1
github.com/iancoleman/strcase v0.3.0
github.com/imroc/req/v3 v3.42.1
github.com/mojocn/base64Captcha v1.3.5
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,8 @@ github.com/goravel/file-rotatelogs/v2 v2.4.1 h1:ogkeIFcTHSBRUBpZYiyJbpul8hkVXxHP
github.com/goravel/file-rotatelogs/v2 v2.4.1/go.mod h1:euk9qr52WrzM8ICs1hecFcR4CZ/ZZOPdacHfvHgbOf0=
github.com/goravel/framework v1.13.1-0.20231104153423-7bfd9573b12d h1:20bsAUUZWGcB8LvCP3nbO+fxGPuwYITiUJGnyx2xUgQ=
github.com/goravel/framework v1.13.1-0.20231104153423-7bfd9573b12d/go.mod h1:5jKFbJzfqhaQTP3HCgbyrpnrCyoJjxN5JWSXO96H0iQ=
github.com/goravel/framework v1.13.1-0.20231105145249-62c723ac8fd1 h1:Bi86UTQtrQIo74ler6NbbXTy0dOGGZaNwtRcBOuZom8=
github.com/goravel/framework v1.13.1-0.20231105145249-62c723ac8fd1/go.mod h1:5jKFbJzfqhaQTP3HCgbyrpnrCyoJjxN5JWSXO96H0iQ=
github.com/gorilla/securecookie v1.1.1/go.mod h1:ra0sb63/xPlUeL+yeDciTfxMRAA+MP+HVt/4epWDjd4=
github.com/gorilla/sessions v1.2.1/go.mod h1:dk2InVEVJ0sfLlnXv9EAgkf6ecYs/i80K/zI+bUmuGM=
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0 h1:UH//fgunKIs4JdUbpDl1VZCDaL56wXCB/5+wF6uHfaI=
Expand Down

0 comments on commit 0a3573b

Please sign in to comment.