paginate

package
v0.0.0-...-0f16109 Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2026 License: AGPL-3.0 Imports: 0 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultMinPageSize uint64 = 10
	DefaultMaxPageSize uint64 = 100
)

Functions

This section is empty.

Types

type Filter

type Filter struct {
	Operation FilterOperation
	Values    []interface{}
}

type FilterOperation

type FilterOperation int
const (
	FilterOperationEqual FilterOperation = iota + 1
	FilterOperationNotEqual
	FilterOperationGreater
	FilterOperationGreaterEqual
	FilterOperationLess
	FilterOperationLessEqual
	FilterOperationIn
	FilterOperationNotIn
	FilterOperationBetween
)

type FilterParameter

type FilterParameter string

FilterParameter defines a key for filtering paginated results. Custom filter parameters can be defined as needed by the application in service layer. Example value include:

  • "status": To filter results by status (e.g, "active", "inactive").
  • "user_id": To filter results by a specific user ID.
  • "created_at": To filter results based on creation date.

type Paginated

type Paginated struct {
	Page       uint64                     `json:"page"`
	PerPage    uint64                     `json:"per_page"`
	Total      uint64                     `json:"total"`
	Filters    map[FilterParameter]Filter `json:"filters"`
	SortColumn string                     `json:"sort_column"`
	Descending bool                       `json:"descending"`
}

Paginated struct represents a paginated response that will be passed to the repository layer to retrieve data based on pagination settings, filters, sorting, etc.

type RequestBase

type RequestBase struct {
	CurrentPage uint64                     `json:"current_page"`
	PageSize    uint64                     `json:"page_size"`
	Filters     map[FilterParameter]Filter `json:"filters"`
	SortColumn  string                     `json:"sort_column"`
	Descending  bool                       `json:"descending"`
}

RequestBase the base structure for pagination requests from the client.

func (*RequestBase) BasicValidation

func (r *RequestBase) BasicValidation() error

BasicValidation just ensure that the pagination request is well-formed. more complex validation should be dome in service layers based on the application's requirements.

type ResponseBase

type ResponseBase struct {
	CurrentPage  uint64 `json:"current_page"`
	PageSize     uint64 `json:"page_size"`
	TotalNumbers uint64 `json:"total_numbers"`
	TotalPage    uint64 `json:"total_page"`
}

ResponseBase the base structure for paginated responses sent to client.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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