valueobject

package
v0.0.0-...-3ca17b7 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PaginationDefaultPage     = 1
	PaginationDefaultPageSize = 10
)

Variables

View Source
var (
	// ExampleValidTags is an example of valid tags. It is used in tests.
	ExampleValidTags = NewTags("tag1", "tag2", "tag3")
	// ExampleInValidTags has more than the maximum number of tags. It is used in tests.
	ExampleInValidTags = func() Tags {
		tags := make([]string, maxNumTags+1)
		for i := 0; i < maxNumTags+1; i++ {
			tags[i] = gofakeit.LetterN(uint(maxTagLength))
		}
		return NewTags(tags...)
	}
	// ExampleInvalidTag is tag with more than the maximum number of characters. It is used in tests.
	ExampleInvalidTag = gofakeit.LetterN(uint(maxTagLength + 1))
)

---- Tags ----

Functions

func IsTagsEqual

func IsTagsEqual(a, b *Tags) bool

IsTagsEqual checks if two tags are equal.

func ValidateTags

func ValidateTags(value any) error

Types

type Pagination

type Pagination struct {
	// contains filtered or unexported fields
}

Pagination is the pagination configuration. Recommended to use `NewPagination` to create a new `Pagination` struct, because it sets default values.

func DefaultPagination

func DefaultPagination() Pagination

func NewPagination

func NewPagination(page, pageSize int) Pagination

NewPagination creates a new `Pagination` struct with default values if none are provided.

func (Pagination) CurrentPage

func (p Pagination) CurrentPage() int

func (Pagination) Limit

func (p Pagination) Limit() int

func (Pagination) Metadata

func (p Pagination) Metadata(totalRecords int) PaginationMetadata

func (Pagination) Offset

func (p Pagination) Offset() int

type PaginationMetadata

type PaginationMetadata struct {
	CurrentPage  int `json:"current_page"`
	PageSize     int `json:"page_size"`
	FirstPage    int `json:"first_page"`
	LastPage     int `json:"last_page"`
	TotalRecords int `json:"total_records"`
}

PaginationMetadata represents the metadata for paginated responses.

func CalculatePaginationMetadata

func CalculatePaginationMetadata(totalRecords, page, pageSize int) PaginationMetadata

CalculatePaginationMetadata calculates the pagination metadata based on the total number of records, the current page, and the page size.

type ReviewInterval

type ReviewInterval struct {
	// contains filtered or unexported fields
}

ReviewInterval represents the interval of time between reviews.

func DefaultReviewIntervals

func DefaultReviewIntervals() ReviewInterval

func ParseReviewInterval

func ParseReviewInterval(interval string) (ReviewInterval, error)

ParseReviewInterval parses the review interval from a string separated by spaces.

func (ReviewInterval) Next

func (r ReviewInterval) Next(i int) time.Time

type Tags

type Tags struct {
	// contains filtered or unexported fields
}

Tags represents a list of tags encapsulated in a struct.

func NewTags

func NewTags(tags ...string) Tags

NewTags creates a new Tags object with the given tags.

NOTE: If the tags array is empty or nil, it will return nil.

func (*Tags) Add

func (t *Tags) Add(tag string)

Add adds a new tag to the list. If the tag already exists, it will not be added again. The tag will be trimmed before adding it to the list.

func (*Tags) AddMany

func (t *Tags) AddMany(tags ...string)

AddMany adds multiple tags to the list. If a tag already exists, it will not be added again.

func (*Tags) AddTags

func (t *Tags) AddTags(tags Tags)

AddTags adds multiple tags to the list.

func (*Tags) Contains

func (t *Tags) Contains(want string) bool

Contains checks if the given tag exists in the list of tags.

func (*Tags) IsEmpty

func (t *Tags) IsEmpty() bool

func (*Tags) Normalize

func (t *Tags) Normalize()

Normalize trims spaces and removes duplicate tags from the list.

func (*Tags) Remove

func (t *Tags) Remove(tag string)

Remove removes a tag from the list. If the tag does not exist, it will not be removed.

func (*Tags) RemoveMany

func (t *Tags) RemoveMany(tags ...string)

RemoveMany removes multiple tags from the list.

func (*Tags) RemoveTags

func (t *Tags) RemoveTags(tags Tags)

RemoveTags removes multiple tags from the list.

func (*Tags) String

func (t *Tags) String() string

func (*Tags) StringArray

func (t *Tags) StringArray() []string

func (*Tags) TrimSpace

func (t *Tags) TrimSpace() Tags

TrimSpace trims spaces from each string in the list and returns a new list.

func (*Tags) Unique

func (t *Tags) Unique() Tags

Unique returns a new list with unique tags.

Jump to

Keyboard shortcuts

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