mirror of
https://github.com/FJurmanovic/wallet-go-api.git
synced 2026-02-06 06:08:16 +00:00
Added filtered GET request
This commit is contained in:
35
pkg/controllers/controllers.go
Normal file
35
pkg/controllers/controllers.go
Normal file
@@ -0,0 +1,35 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
"wallet-api/pkg/models"
|
||||
"wallet-api/pkg/utl/common"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func FilteredResponse(c *gin.Context) *models.FilteredResponse {
|
||||
filtered := new(models.FilteredResponse)
|
||||
page, _ := c.GetQuery("page")
|
||||
rpp, _ := c.GetQuery("rpp")
|
||||
sortBy, _ := c.GetQuery("sortBy")
|
||||
|
||||
dividers := [5]string{"|", " ", ".", "/", ","}
|
||||
|
||||
for _, div := range dividers {
|
||||
sortArr := strings.Split(sortBy, div)
|
||||
|
||||
if len(sortArr) >= 2 {
|
||||
sortBy = fmt.Sprintf("%s %s", common.ToSnakeCase(sortArr[0]), strings.ToUpper(sortArr[1]))
|
||||
}
|
||||
}
|
||||
|
||||
filtered.Embed, _ = c.GetQuery("embed")
|
||||
filtered.Page, _ = strconv.Atoi(page)
|
||||
filtered.Rpp, _ = strconv.Atoi(rpp)
|
||||
filtered.SortBy = sortBy
|
||||
|
||||
return filtered
|
||||
}
|
||||
Reference in New Issue
Block a user