example

package
v0.0.0-...-d8a7a92 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2025 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultExampleSortQuery

func DefaultExampleSortQuery() q.SortQuery[SortEntry]

DefaultExampleSortQuery returns the default sort configuration for Example

func ExampleRouter

func ExampleRouter(r *chi.Mux, ns string, c ExampleController)

ExampleRouter implements a router group for an Example resource

func NewController

func NewController(c *ControllerConfig) (*exampleController, error)

NewController returns a new Controller instance

func NewExampleRepository

func NewExampleRepository(c *ExampleRepoConfig) (*exampleRepository, error)

NewExampleRepository returns a new exampleRepository instance

func NewExampleService

func NewExampleService(c *ExampleServiceConfig) (*exampleService, error)

NewExampleService returns a new exampleService instance

Types

type ControllerConfig

type ControllerConfig struct {
	Logger  *logger.CustomLogger `validate:"required"`
	Query   *ExampleQueryHandler `validate:"required"`
	Service ExampleService       `validate:"required"`
}

ControllerConfig defines the input to NewController

type ExampleController

type ExampleController interface {
	Create(func() *jsonapi.RequestBody) http.HandlerFunc
	Delete() http.HandlerFunc
	Detail() http.HandlerFunc
	List() http.HandlerFunc
	Update(func() *jsonapi.RequestBody) http.HandlerFunc
}

ExampleController

type ExampleDTORequest

type ExampleDTORequest struct {
	Description *string `json:"description" validate:"omitempty,min=3,max=999"`
	Title       string  `json:"title" validate:"required,omitempty,min=2,max=255"`
}

ExampleDTORequest defines the subset of Example domain model attributes that are accepted for input data request binding

func (ExampleDTORequest) Validate

func (e ExampleDTORequest) Validate() error

Validate validates an Example request DTO

type ExampleEntity

type ExampleEntity struct {
	ID              uuid.UUID
	Title           string
	Description     sql.NullString
	Status          repo.RecordStatus
	CreatedOn       time.Time
	CreatedContext  []byte // JSONB field
	ModifiedOn      time.Time
	ModifiedContext []byte // JSONB field
}

ExampleEntity defines an Example database entity

type ExampleEntityModel

type ExampleEntityModel struct {
	Record ExampleEntity
}

type ExampleModel

type ExampleModel struct {
	Meta       any
	Attributes ModelAttributes
}

ExampleModel

type ExampleQueryData

type ExampleQueryData q.QueryData[SortEntry]

type ExampleQueryHandler

type ExampleQueryHandler q.QueryHandler[SortEntry]

func NewExampleQueryHandler

func NewExampleQueryHandler(c *q.QueryConfig[SortEntry]) (*ExampleQueryHandler, error)

NewExampleQueryHandler creates a new query handler for the Example module

func (*ExampleQueryHandler) ParseQuery

func (h *ExampleQueryHandler) ParseQuery(qs []byte) *ExampleQueryData

ParseQuery parses query parameters for the Example module

type ExampleRepoConfig

type ExampleRepoConfig struct {
	DBClient *pgxpool.Pool        `validate:"required"`
	Logger   *logger.CustomLogger `validate:"required"`
}

ExampleRepoConfig defines the input to NewExampleRepository

type ExampleRepository

ExampleRepository defines the interface for a repository managing the Example domain/entity model

type ExampleService

ExampleService

type ExampleServiceConfig

type ExampleServiceConfig struct {
	Logger *logger.CustomLogger `validate:"required"`
	Repo   ExampleRepository    `validate:"required"`
}

ExampleServiceConfig defines the input to NewExampleService

type ExampleSortMetadata

type ExampleSortMetadata q.SortMetadata[SortEntry]

ExampleSortMetadata defines the Example sorting-related response metadata Currently mirrors SortQuery structure but kept separate for potential changes

type ExampleSortQuery

type ExampleSortQuery q.SortQuery[SortEntry]

ExampleSortQuery represents an array of sort entries

type FilterMetadata

type FilterMetadata struct {
	Title *string `schema:"title"`
}

FilterMetadata defines the filter-related response query parameters

type FilterQuery

type FilterQuery struct {
	Title *string `schema:"title" json:"title,omitempty"`
}

FilterQuery defines the filter-related request query paramaters filtered[title]=test

type ListQueryData

type ListQueryData struct {
	Page repo.PageData
	Sort ExampleSortMetadata
}

type ModelAttributes

type ModelAttributes struct {
	ID          uuid.UUID  `json:"-"`
	Title       string     `json:"title"`
	Description *string    `json:"description"`
	Status      *uint32    `json:"status"`
	Enabled     bool       `json:"enabled"`
	Deleted     bool       `json:"-"`
	CreatedOn   time.Time  `json:"created_on"`
	CreatedBy   uint32     `json:"created_by"`
	ModifiedOn  *time.Time `json:"modified_on"`
	ModifiedBy  *uint32    `json:"modified_by"`
}

Example defines an Example domain model for application logic

type ModelContainer

type ModelContainer struct {
	Data []ExampleModel
	Meta *ModelContainerMeta
	Solo bool
}

ModelContainer contains one or more ExampleModel(s) and related metadata

func MarshalEntityModel

func MarshalEntityModel(em *ExampleEntityModel) *ModelContainer

func MarshalEntityModelList

func MarshalEntityModelList(ems []*ExampleEntityModel, lqd ListQueryData) *ModelContainer

func (*ModelContainer) FormatResponse

func (m *ModelContainer) FormatResponse() (*jsonapi.Response, error)

type ModelContainerMeta

type ModelContainerMeta struct {
	Filter *query.FilterMetadata `json:"filter,omitempty"`
	Page   query.PageMetadata    `json:"page,omitempty"`
	Sort   ExampleSortMetadata   `json:"sort,omitempty"`
}

func MarshalListMetadata

func MarshalListMetadata(lqd ListQueryData) *ModelContainerMeta

type SortEntry

type SortEntry struct {
	CreatedOn  *q.SortOrder `schema:"created_on" json:"created_on,omitempty"`
	ModifiedOn *q.SortOrder `schema:"modified_on" json:"modified_on,omitempty"`
	Title      *q.SortOrder `schema:"title" json:"title,omitempty"`
}

SortEntry represents a single SortQuery element with defined sortable fields

func CreateSortEntry

func CreateSortEntry() SortEntry

CreateSortEntry is a factory function for creating new SortEntry instances

func (SortEntry) GetActiveFields

func (se SortEntry) GetActiveFields() map[string]q.SortOrder

GetActiveFields returns a map of active field names and their orders

func (SortEntry) GetFieldCount

func (se SortEntry) GetFieldCount() int

GetFieldCount returns the number of non-nil fields in the entry

func (SortEntry) GetSortPairs

func (se SortEntry) GetSortPairs() []struct {
	Field string
	Order q.SortOrder
}

GetSortPairs returns field-order pairs for database queries

func (SortEntry) GetValidFieldNames

func (se SortEntry) GetValidFieldNames() []string

GetValidFieldNames returns a list of valid field names for this entry type

func (SortEntry) HasAnyField

func (se SortEntry) HasAnyField() bool

HasAnyField returns true if at least one field is set

func (SortEntry) SetFieldFromString

func (se SortEntry) SetFieldFromString(fieldName string, order q.SortOrder) (q.SortableEntry, error)

SetFieldFromString sets a field by name from a string value

Jump to

Keyboard shortcuts

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