utils

package
v0.0.0-...-4d127bd Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Dirname

func Dirname() (string, error)

Dirname returns the directory path of the current file where it is called.

func HashPassword

func HashPassword(password string) (string, error)

HashPassword hashes a plaintext password using bcrypt. It takes the plaintext password as input and returns the hashed password and any error that occurs during hashing.

Types

type FilterModel

type FilterModel struct {
	Field      string `query:"field" json:"field"`
	Value      string `query:"value" json:"value"`
	Comparison string `query:"comparison" json:"comparison"`
}

FilterModel defines the structure for filtering query results.

type ListQuery

type ListQuery struct {
	Size    int            `query:"size" json:"size,omitempty"`
	Page    int            `query:"page" json:"page,omitempty"`
	OrderBy string         `query:"orderBy" json:"orderBy,omitempty"`
	Filters []*FilterModel `query:"filters" json:"filters,omitempty"`
}

ListQuery represents the parameters for querying a paginated list.

func (*ListQuery) GetLimit

func (q *ListQuery) GetLimit() int

GetLimit returns the maximum number of items to retrieve, based on the page size.

func (*ListQuery) GetOffset

func (q *ListQuery) GetOffset() int

GetOffset calculates the offset for the database query based on the current page and page size.

func (*ListQuery) GetOrderBy

func (q *ListQuery) GetOrderBy() string

GetOrderBy returns the field by which the results should be ordered.

func (*ListQuery) GetPage

func (q *ListQuery) GetPage() int

GetPage returns the current page number from the ListQuery.

func (*ListQuery) GetSize

func (q *ListQuery) GetSize() int

GetSize returns the number of items per page from the ListQuery.

type ListResult

type ListResult[T interface{}] struct {
	Size       int   `json:"size,omitempty" bson:"size"`
	Page       int   `json:"page,omitempty" bson:"page"`
	TotalItems int64 `json:"totalItems,omitempty" bson:"totalItems"`
	TotalPage  int   `json:"totalPage,omitempty" bson:"totalPage"`
	Items      []T   `json:"items,omitempty" bson:"items"`
}

ListResult encapsulates the result of a paginated query.

func NewListResult

func NewListResult[T any](items []T, size int, page int, totalItems int64) *ListResult[T]

NewListResult constructs a new ListResult instance.

Jump to

Keyboard shortcuts

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