pagi

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 11, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetAPIEndpoint

func GetAPIEndpoint(host, path string) string

func NewOrderBy

func NewOrderBy(params SortParams) string

NewOrderBy constructs the ORDER BY clause based on sorting parameters

Types

type PagingInfo

type PagingInfo[T interface{}] struct {
	Links      PagingLinks `json:"links"`
	Total      int64       `json:"total"`
	Page       int         `json:"page"`
	PageSize   int         `json:"page_size"`
	TotalPages int         `json:"total_pages"`
	Rows       T           `json:"rows,omitempty"`
}

func Paginate

func Paginate[FT any, T any](p PagingParams[FT], query *gorm.DB) (PagingInfo[T], error)
type PagingLinks struct {
	Next     string `json:"next"`
	Previous string `json:"previous"`
}

PaginationLinks contains links for next and previous pages.

type PagingParams

type PagingParams[FilterType interface{}] struct {
	Limit      int        `json:"limit"`
	Page       int        `json:"page"`
	Sort       string     `json:"sort"`
	Order      string     `json:"order"`
	TotalRows  int64      `json:"total_rows"`
	TotalPages int        `json:"total_pages"`
	BaseURL    string     `json:"base_url"`
	Filters    FilterType `json:"filters"`
}

func InitPagingParams

func InitPagingParams[FilterType interface{}](host string, sort string, order string, page string, pageSize string, defaultSort string) PagingParams[FilterType]

func (*PagingParams[FilterType]) GetLimit

func (p *PagingParams[FilterType]) GetLimit() int

func (*PagingParams[FilterType]) GetOffset

func (p *PagingParams[FilterType]) GetOffset() int

func (*PagingParams[FilterType]) GetPage

func (p *PagingParams[FilterType]) GetPage() int

func (*PagingParams[FilterType]) GetSort

func (p *PagingParams[FilterType]) GetSort() string

type SortParams

type SortParams struct {
	Sort           string // Field to sort by
	Order          string // Sorting order ("ASC" or "DESC")
	DefaultOrderBy string // Default
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL