Documentation
¶
Index ¶
- func DefaultExampleSortQuery() q.SortQuery[SortEntry]
- func ExampleRouter(r *chi.Mux, ns string, c ExampleController)
- func NewController(c *ControllerConfig) (*exampleController, error)
- func NewExampleRepository(c *ExampleRepoConfig) (*exampleRepository, error)
- func NewExampleService(c *ExampleServiceConfig) (*exampleService, error)
- type ControllerConfig
- type ExampleController
- type ExampleDTORequest
- type ExampleEntity
- type ExampleEntityModel
- type ExampleModel
- type ExampleQueryData
- type ExampleQueryHandler
- type ExampleRepoConfig
- type ExampleRepository
- type ExampleService
- type ExampleServiceConfig
- type ExampleSortMetadata
- type ExampleSortQuery
- type FilterMetadata
- type FilterQuery
- type ListQueryData
- type ModelAttributes
- type ModelContainer
- type ModelContainerMeta
- type SortEntry
- func (se SortEntry) GetActiveFields() map[string]q.SortOrder
- func (se SortEntry) GetFieldCount() int
- func (se SortEntry) GetSortPairs() []struct{ ... }
- func (se SortEntry) GetValidFieldNames() []string
- func (se SortEntry) HasAnyField() bool
- func (se SortEntry) SetFieldFromString(fieldName string, order q.SortOrder) (q.SortableEntry, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultExampleSortQuery ¶
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 ExampleQueryData ¶
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 ¶
type ExampleRepository interface {
Create(context.Context, *ExampleDTORequest) (*ModelContainer, error)
Delete(context.Context, uuid.UUID) error
Detail(context.Context, uuid.UUID) (*ModelContainer, error)
List(context.Context, ExampleQueryData) (*ModelContainer, error)
Update(context.Context, *ExampleDTORequest, uuid.UUID) (*ModelContainer, error)
}
ExampleRepository defines the interface for a repository managing the Example domain/entity model
type ExampleService ¶
type ExampleService interface {
Create(context.Context, any) (*ModelContainer, error)
Delete(context.Context, uuid.UUID) error
Detail(context.Context, uuid.UUID) (*ModelContainer, error)
List(context.Context, ExampleQueryData) (*ModelContainer, error)
Update(context.Context, any, uuid.UUID) (*ModelContainer, error)
}
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 ¶
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 ¶
GetActiveFields returns a map of active field names and their orders
func (SortEntry) GetFieldCount ¶
GetFieldCount returns the number of non-nil fields in the entry
func (SortEntry) GetSortPairs ¶
GetSortPairs returns field-order pairs for database queries
func (SortEntry) GetValidFieldNames ¶
GetValidFieldNames returns a list of valid field names for this entry type
func (SortEntry) HasAnyField ¶
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