Skip to content

Commit

Permalink
refactor: use Fiber's new query parameter helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
bfabio committed Jun 16, 2023
1 parent 9ae30c5 commit 5d67ae6
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 10 deletions.
12 changes: 4 additions & 8 deletions internal/handlers/general/pagination.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package general
import (
"encoding/json"
"fmt"
"strconv"

"github.com/gofiber/fiber/v2"
"github.com/pilagod/gorm-cursor-paginator/v2/paginator"
Expand Down Expand Up @@ -48,13 +47,10 @@ func NewPaginatorWithConfig(ctx *fiber.Ctx, config *paginator.Config) *paginator
paginator.SetBeforeCursor(before)
}

if size := ctx.Query("page[size]"); size != "" {
//nolint:godox // need to implement this in the future
// TODO: make the API return the error if limit is not an integer
if limit, err := strconv.Atoi(size); err == nil {
paginator.SetLimit(limit)
}
}
//nolint:godox // need to implement this in the future
// TODO: make the API return the error if limit is not an integer
size := ctx.QueryInt("page[size]", DefaultLimitCount)
paginator.SetLimit(size)

return paginator
}
Expand Down
2 changes: 1 addition & 1 deletion internal/handlers/publishers.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (p *Publisher) GetPublishers(ctx *fiber.Ctx) error {

stmt := p.db.Preload("CodeHosting")

if all := ctx.Query("all", ""); all == "" {
if all := ctx.QueryBool("all", false); !all {
stmt = stmt.Scopes(models.Active)
}

Expand Down
2 changes: 1 addition & 1 deletion internal/handlers/software.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func (p *Software) GetAllSoftware(ctx *fiber.Ctx) error { //nolint:cyclop // mos

stmt.Where("id = ?", softwareURL.SoftwareID)
} else {
if all := ctx.Query("all", ""); all == "" {
if all := ctx.QueryBool("all", false); !all {
stmt = stmt.Scopes(models.Active)
}
}
Expand Down

0 comments on commit 5d67ae6

Please sign in to comment.