meta

package
v0.0.0-...-31b340c Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PageField  = "page"
	LimitField = "limit"
)

Variables

This section is empty.

Functions

func Paginate

func Paginate(config PaginateRequest) func(db *gorm.DB) *gorm.DB

Paginate is a middleware that paginates the query result based on the given configuration.

func Sort

func Sort(config map[string]SorterEnum, valid ValidSortColumns) func(db *gorm.DB) *gorm.DB

Sort is a middleware that sorts the query result based on the given configuration.

Types

type Abstraction

type Abstraction[T any] interface {
	Set(qry T) DomainWrapper[T]
}

func NewRequest

func NewRequest[T any](ctx *gin.Context) Abstraction[T]

type Collect

type Collect[T any] interface {
	GetDomainData() []T
	ToDomain(data []T) Collect[T]
	GetMeta(ctx *gin.Context) Meta
}

func NewCollection

func NewCollection[T any](data any) Collect[T]

NewCollection creates a new collection.

type DomainWrapper

type DomainWrapper[T any] struct {
	// contains filtered or unexported fields
}

func (DomainWrapper[T]) GetPagination

func (t DomainWrapper[T]) GetPagination() PaginateRequest

func (DomainWrapper[T]) GetQry

func (t DomainWrapper[T]) GetQry() T

func (DomainWrapper[T]) GetSort

func (t DomainWrapper[T]) GetSort() map[string]SorterEnum

type Meta

type Meta struct {
	Pagination Pagination `json:"pagination"`
}

type PaginateRequest

type PaginateRequest struct {
	Limit       int
	Page        int
	HasPaginate bool
}

func (PaginateRequest) GetLimit

func (p PaginateRequest) GetLimit() int

func (PaginateRequest) GetOffset

func (p PaginateRequest) GetOffset() int

type Pagination

type Pagination struct {
	Page       int `json:"page"`
	PerPage    int `json:"perPage"`
	PageCount  int `json:"pageCount"`
	TotalCount int `json:"totalCount"`
}

type Paginator

type Paginator interface {
	GetPaginator() WithPaginator
}

type SorterEnum

type SorterEnum string
const (
	SorterEnumAsc  SorterEnum = "ASC"
	SorterEnumDesc SorterEnum = "DESC"
)

type ValidSortColumns

type ValidSortColumns []string

type WithPaginator

type WithPaginator struct {
	TotalCount int `gorm:"->"`
}

Jump to

Keyboard shortcuts

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