Documentation
¶
Index ¶
- Variables
- func CreateInvoke[Entity database.Mutator](ctx context.Context, connFn db.ConnFn, entity Entity, ...) (Entity, error)
- func DeleteInvoke[Entity database.Mutator](ctx context.Context, parsedInput *ParsedDeleteEndpointInput, connFn db.ConnFn, ...) (int64, error)
- func GetInvoke[Entity database.Getter](ctx context.Context, parsedInput *ParsedGetEndpointInput, connFn db.ConnFn, ...) ([]Entity, int, error)
- func UpdateInvoke[Entity database.Mutator](ctx context.Context, parsedInput *ParsedUpdateEndpointInput, connFn db.ConnFn, ...) (int64, error)
- type AfterCreate
- type AfterDelete
- type AfterGet
- type AfterUpdate
- type BeforeCreateCallback
- type BeforeDeleteCallback
- type BeforeGetCallback
- type BeforeUpdateCallback
- type CreateEntityFactoryFn
- type CreateHandler
- func (h *CreateHandler[Entity]) Handle(w http.ResponseWriter, r *http.Request, i *CreateInputer[Entity]) (any, error)
- func (h *CreateHandler[Entity]) WithBeforeCallback(beforeCallback BeforeCreateCallback[Entity]) *CreateHandler[Entity]
- func (h *CreateHandler[Entity]) WithCreateInvokeFn(createInvokeFn CreateInvokeFn[Entity]) *CreateHandler[Entity]
- func (h *CreateHandler[Entity]) WithEntityFactoryFn(entityFactoryFn CreateEntityFactoryFn[Entity]) *CreateHandler[Entity]
- func (h *CreateHandler[Entity]) WithToOutputFn(toOutputFn ToCreateOutputFn[Entity]) *CreateHandler[Entity]
- type CreateInputer
- type CreateInvokeFn
- type CreateOutputer
- type DeleteEntityFactoryFn
- type DeleteHandler
- func (h *DeleteHandler[Entity]) Handle(w http.ResponseWriter, r *http.Request, i *DeleteInputer) (any, error)
- func (h *DeleteHandler[Entity]) WithBeforeDeleteCallback(beforeCallback BeforeDeleteCallback[Entity]) *DeleteHandler[Entity]
- func (h *DeleteHandler[Entity]) WithDeleteInvokeFn(deleteInvokeFn DeleteInvokeFn[Entity]) *DeleteHandler[Entity]
- func (h *DeleteHandler[Entity]) WithEntityFactoryFn(entityFactoryFn DeleteEntityFactoryFn[Entity]) *DeleteHandler[Entity]
- func (h *DeleteHandler[Entity]) WithParseInputFn(parseInputFn func(input DeleteInputer) (*ParsedDeleteEndpointInput, error)) *DeleteHandler[Entity]
- func (h *DeleteHandler[Entity]) WithToOutputFn(toOutputFn ToDeleteOutputFn) *DeleteHandler[Entity]
- type DeleteInputer
- type DeleteInvokeFn
- type DeleteOutputer
- type GetHandler
- func (h *GetHandler[Entity]) Handle(w http.ResponseWriter, r *http.Request, i *GetInputer) (any, error)
- func (h *GetHandler[Entity]) WithBeforeCallback(beforeCallback BeforeGetCallback) *GetHandler[Entity]
- func (h *GetHandler[Entity]) WithEntityFactoryFn(entityFactoryFn db.GetterFactoryFn[Entity]) *GetHandler[Entity]
- func (h *GetHandler[Entity]) WithGetInvokeFn(getInvokeFn GetInvokeFn[Entity]) *GetHandler[Entity]
- func (h *GetHandler[Entity]) WithParseInputFn(parseInputFn func(input *GetInputer) (*ParsedGetEndpointInput, error)) *GetHandler[Entity]
- func (h *GetHandler[Entity]) WithToOutputFn(toOutputFn ToGetOutputFn[Entity]) *GetHandler[Entity]
- type GetInputer
- type GetInvokeFn
- type GetOutputer
- type ParsedDeleteEndpointInput
- type ParsedGetEndpointInput
- type ParsedUpdateEndpointInput
- type ToCreateOutputFn
- type ToDeleteOutputFn
- type ToGetOutputFn
- type ToUpdateOutputFn
- type UpdateEntityFactoryFn
- type UpdateHandler
- func (h *UpdateHandler[Entity]) Handle(w http.ResponseWriter, r *http.Request, i *UpdateInputer) (any, error)
- func (h *UpdateHandler[Entity]) WithBeforeUpdateCallback(beforeCallback BeforeUpdateCallback[Entity]) *UpdateHandler[Entity]
- func (h *UpdateHandler[Entity]) WithEntityFactoryFn(entityFactoryFn UpdateEntityFactoryFn[Entity]) *UpdateHandler[Entity]
- func (h *UpdateHandler[Entity]) WithParseInputFn(parseInputFn func(input *UpdateInputer) (*ParsedUpdateEndpointInput, error)) *UpdateHandler[Entity]
- func (h *UpdateHandler[Entity]) WithToOutputFn(toOutputFn ToUpdateOutputFn) *UpdateHandler[Entity]
- func (h *UpdateHandler[Entity]) WithUpdateInvokeFn(updateInvokeFn UpdateInvokeFn[Entity]) *UpdateHandler[Entity]
- type UpdateInputer
- type UpdateInvokeFn
- type UpdateOutputer
Constants ¶
This section is empty.
Variables ¶
var ( ErrNeedAtLeastOneSelector = apierror.NewAPIError("NEED_AT_LEAST_ONE_SELECTOR") ErrNeedAtLeastOneUpdate = apierror.NewAPIError("NEED_AT_LEAST_ONE_UPDATE") )
Common errors.
Functions ¶
func CreateInvoke ¶
func CreateInvoke[Entity database.Mutator]( ctx context.Context, connFn db.ConnFn, entity Entity, mutatorRepo db.MutatorRepository[Entity], txManager db.TxManager[Entity], afterCreateFn AfterCreate[Entity], ) (Entity, error)
CreateInvoke executes the create operation.
Parameters:
- ctx: The context.
- connFn: The database connection function.
- entity: The entity to create.
- mutatorRepo: The mutator repository.
- txManager: The transaction manager.
Returns:
- Entity: The created entity.
- error: Any error that occurred during the operation.
func DeleteInvoke ¶
func DeleteInvoke[Entity database.Mutator]( ctx context.Context, parsedInput *ParsedDeleteEndpointInput, connFn db.ConnFn, entity Entity, mutatorRepo db.MutatorRepository[Entity], txManager db.TxManager[*int64], afterDeleteFn AfterDelete, ) (int64, error)
DeleteInvoke executes the delete operation.
Parameters:
- ctx: The context.
- connFn: The database connection function.
- entity: The entity to delete.
- mutatorRepo: The mutator repository.
- txManager: The transaction manager.
Returns:
- int64: The number of entities deleted.
- error: Any error that occurred during the operation.
func GetInvoke ¶
func GetInvoke[Entity database.Getter]( ctx context.Context, parsedInput *ParsedGetEndpointInput, connFn db.ConnFn, entityFactoryFn db.GetterFactoryFn[Entity], readerRepo db.ReaderRepository[Entity], _ db.TxManager[Entity], afterGetFn AfterGet[Entity], ) ([]Entity, int, error)
GetInvoke executes the get operation.
Parameters:
- ctx: The context.
- connFn: The database connection function.
- entityFactoryFn: The entity factory function.
- readerRepo: The reader repository.
- txManager: The transaction manager.
Returns:
- []Entity: The entities.
- error: Any error that occurred during the operation.
func UpdateInvoke ¶
func UpdateInvoke[Entity database.Mutator]( ctx context.Context, parsedInput *ParsedUpdateEndpointInput, connFn db.ConnFn, entity Entity, mutatorRepo db.MutatorRepository[Entity], txManager db.TxManager[*int64], afterUpdateFn AfterUpdate[Entity], ) (int64, error)
UpdateInvoke executes the update operation.
Parameters:
- ctx: The context.
- connFn: The database connection function.
- entity: The entity to update.
- mutatorRepo: The mutator repository.
- txManager: The transaction manager.
Returns:
- int64: The number of entities updated.
- error: Any error that occurred during the operation.
Types ¶
type AfterCreate ¶
type AfterCreate[Entity database.Mutator] func( ctx context.Context, tx database.Tx, entity Entity, ) (Entity, error)
AfterCreate is a function that is called after a create operation.
type AfterDelete ¶
AfterDelete is a function that is called after a delete operation.
type AfterGet ¶
type AfterGet[Entity database.Getter] func( ctx context.Context, tx database.Tx, count int, ) ([]Entity, int, error)
AfterGet is a function that is called after a get operation.
type AfterUpdate ¶
type AfterUpdate[Entity database.Mutator] func( ctx context.Context, tx database.Tx, count int64, ) (*int64, error)
AfterUpdate is a function that is called after an update operation.
type BeforeCreateCallback ¶
type BeforeCreateCallback[Entity database.Mutator] func( w http.ResponseWriter, r *http.Request, entity Entity, input CreateInputer[Entity], ) (Entity, error)
BeforeCreateCallback is the function that runs before the create operation. It can be used to modify the entity before it is created.
type BeforeDeleteCallback ¶
type BeforeDeleteCallback[Entity database.Mutator] func( w http.ResponseWriter, r *http.Request, parsedInput *ParsedDeleteEndpointInput, entity Entity, input DeleteInputer, ) (*ParsedDeleteEndpointInput, Entity, error)
BeforeDeleteCallback is the function that runs before the delete operation. It can be used to modify the parsed input and entity before they are used.
type BeforeGetCallback ¶
type BeforeGetCallback func( w http.ResponseWriter, r *http.Request, parsedInput *ParsedGetEndpointInput, input *GetInputer, ) (*ParsedGetEndpointInput, error)
BeforeGetCallback is the function that runs before the get operation. It can be used to modify the parsed input before it is used.
type BeforeUpdateCallback ¶
type BeforeUpdateCallback[Entity database.Mutator] func( w http.ResponseWriter, r *http.Request, parsedInput *ParsedUpdateEndpointInput, entity Entity, input *UpdateInputer, ) (*ParsedUpdateEndpointInput, Entity, error)
BeforeUpdateCallback is the function that runs before the update operation. It can be used to modify the parsed input and entity before they are used.
type CreateEntityFactoryFn ¶
type CreateEntityFactoryFn[Entity database.Mutator] func( ctx context.Context, input *CreateInputer[Entity], ) (Entity, error)
CreateEntityFactoryFn is the function that creates a new entity.
type CreateHandler ¶
CreateHandler is the handler implementation for the create endpoint.
func NewCreateHandler ¶
func NewCreateHandler[Entity database.Mutator]( entityFactoryFn CreateEntityFactoryFn[Entity], createInvokeFn CreateInvokeFn[Entity], toOutputFn ToCreateOutputFn[Entity], beforeCallback BeforeCreateCallback[Entity], ) *CreateHandler[Entity]
NewCreateHandler creates a new create handler.
Parameters:
- entityFactoryFn: The function that creates a new entity.
- createInvokeFn: The function that invokes the create endpoint.
- toOutputFn: The function that converts the entity to the endpoint output.
- beforeCallback: The optional function that runs before the create operation.
Returns:
- *CreateHandler: The new create handler.
func (*CreateHandler[Entity]) Handle ¶
func (h *CreateHandler[Entity]) Handle( w http.ResponseWriter, r *http.Request, i *CreateInputer[Entity], ) (any, error)
Handle processes the create endpoint.
Parameters:
- w: The response writer.
- r: The request.
- i: The input.
Returns:
- any: The endpoint output.
- error: An error if the request fails.
func (*CreateHandler[Entity]) WithBeforeCallback ¶
func (h *CreateHandler[Entity]) WithBeforeCallback( beforeCallback BeforeCreateCallback[Entity], ) *CreateHandler[Entity]
WithBeforeCallback returns a new create handler with the before callback.
Parameters:
- beforeCallback: The function that runs before the create operation.
Returns:
- *CreateHandler: The new create handler.
func (*CreateHandler[Entity]) WithCreateInvokeFn ¶
func (h *CreateHandler[Entity]) WithCreateInvokeFn( createInvokeFn CreateInvokeFn[Entity], ) *CreateHandler[Entity]
WithCreateInvokeFn returns a new create handler with the create invoke function.
Parameters:
- createInvokeFn: The function that invokes the create endpoint.
Returns:
- *CreateHandler: The new create handler.
func (*CreateHandler[Entity]) WithEntityFactoryFn ¶
func (h *CreateHandler[Entity]) WithEntityFactoryFn( entityFactoryFn CreateEntityFactoryFn[Entity], ) *CreateHandler[Entity]
WithEntityFactoryFn returns a new create handler with the entity factory function.
Parameters:
- entityFactoryFn: The function that creates a new entity.
Returns:
- *CreateHandler: The new create handler.
func (*CreateHandler[Entity]) WithToOutputFn ¶
func (h *CreateHandler[Entity]) WithToOutputFn( toOutputFn ToCreateOutputFn[Entity], ) *CreateHandler[Entity]
WithToOutputFn returns a new create handler with the to output function.
Parameters:
- toOutputFn: The function that converts the entity to the endpoint output.
Returns:
- *CreateHandler: The new create handler.
type CreateInputer ¶
type CreateInputer[Entity any] interface { GetEntity() Entity }
CreateInputer is the input interface for the create endpoint.
type CreateInvokeFn ¶
type CreateInvokeFn[Entity database.Mutator] func( ctx context.Context, entity Entity, ) (Entity, error)
CreateInvokeFn is the function invokes the create endpoint.
type CreateOutputer ¶
type CreateOutputer[Entity any] interface { SetEntities(entities []Entity) }
CreateOutputer is the output interface for the create endpoint.
type DeleteEntityFactoryFn ¶
DeleteEntityFactoryFn is the function that creates a new entity.
type DeleteHandler ¶
DeleteHandler is the handler implementation for the delete endpoint.
func NewDeleteHandler ¶
func NewDeleteHandler[Entity database.Mutator]( parseInputFn func( input DeleteInputer, ) (*ParsedDeleteEndpointInput, error), deleteInvokeFn DeleteInvokeFn[Entity], toOutputFn ToDeleteOutputFn, entityFactoryFn DeleteEntityFactoryFn[Entity], beforeCallback BeforeDeleteCallback[Entity], ) *DeleteHandler[Entity]
NewDeleteHandler creates a new delete handler.
Parameters:
- parseInputFn: The function that parses the db.
- deleteInvokeFn: The function that invokes the delete endpoint.
- toOutputFn: The function that converts the entities to the endpoint output.
- entityFactoryFn: The function that creates a new entity.
- beforeCallback: The optional function that runs before the delete operation.
Returns:
- *DeleteHandler: The new delete handler.
func (*DeleteHandler[Entity]) Handle ¶
func (h *DeleteHandler[Entity]) Handle( w http.ResponseWriter, r *http.Request, i *DeleteInputer, ) (any, error)
Handle processes the delete endpoint.
Parameters:
- w: The response writer.
- r: The request.
- i: The db.
Returns:
- any: The endpoint output.
- error: An error if the request fails.
func (*DeleteHandler[Entity]) WithBeforeDeleteCallback ¶
func (h *DeleteHandler[Entity]) WithBeforeDeleteCallback( beforeCallback BeforeDeleteCallback[Entity], ) *DeleteHandler[Entity]
WithBeforeDeleteCallback returns a new delete handler with the before delete callback.
Parameters:
- beforeCallback: The function that runs before the delete operation.
Returns:
- *DeleteHandler: The new delete handler.
func (*DeleteHandler[Entity]) WithDeleteInvokeFn ¶
func (h *DeleteHandler[Entity]) WithDeleteInvokeFn( deleteInvokeFn DeleteInvokeFn[Entity], ) *DeleteHandler[Entity]
WithDeleteInvokeFn returns a new delete handler with the delete invoke function.
Parameters:
- deleteInvokeFn: The function that invokes the delete endpoint.
Returns:
- *DeleteHandler: The new delete handler.
func (*DeleteHandler[Entity]) WithEntityFactoryFn ¶
func (h *DeleteHandler[Entity]) WithEntityFactoryFn( entityFactoryFn DeleteEntityFactoryFn[Entity], ) *DeleteHandler[Entity]
WithEntityFactoryFn returns a new delete handler with the entity factory function.
Parameters:
- entityFactoryFn: The function that creates a new entity.
Returns:
- *DeleteHandler: The new delete handler.
func (*DeleteHandler[Entity]) WithParseInputFn ¶
func (h *DeleteHandler[Entity]) WithParseInputFn( parseInputFn func( input DeleteInputer, ) (*ParsedDeleteEndpointInput, error), ) *DeleteHandler[Entity]
WithParseInputFn returns a new delete handler with the parse input function.
Parameters:
- parseInputFn: The function that parses the db.
Returns:
- *DeleteHandler: The new delete handler.
func (*DeleteHandler[Entity]) WithToOutputFn ¶
func (h *DeleteHandler[Entity]) WithToOutputFn( toOutputFn ToDeleteOutputFn, ) *DeleteHandler[Entity]
WithToOutputFn returns a new delete handler with the to output function.
Parameters:
- toOutputFn: The function that converts the entities to the endpoint output.
Returns:
- *DeleteHandler: The new delete handler.
type DeleteInputer ¶
type DeleteInputer interface {
GetSelectors() apidb.APISelectors
}
type DeleteInvokeFn ¶
type DeleteInvokeFn[Entity database.Mutator] func( ctx context.Context, parsedInput *ParsedDeleteEndpointInput, entity Entity, ) (int64, error)
DeleteInvokeFn is the function that invokes the delete endpoint.
type DeleteOutputer ¶
type DeleteOutputer interface {
SetCount(count int64)
}
type GetHandler ¶
GetHandler is the handler for the get endpoint.
func NewGetHandler ¶
func NewGetHandler[Entity database.Getter]( parseInputFn func( input *GetInputer, ) (*ParsedGetEndpointInput, error), getInvokeFn GetInvokeFn[Entity], toOutputFn ToGetOutputFn[Entity], entityFactoryFn db.GetterFactoryFn[Entity], beforeCallback BeforeGetCallback, ) *GetHandler[Entity]
NewGetHandler creates a new get handler.
Parameters:
- parseInputFn: The function that parses the db.
- getInvokeFn: The function that invokes the get endpoint.
- toOutputFn: The function that converts the entities to the endpoint output.
- entityFactoryFn: The function that creates a new entity.
- beforeCallback: The optional function that runs before the get operation.
Returns:
- *GetHandler: The new get handler.
func (*GetHandler[Entity]) Handle ¶
func (h *GetHandler[Entity]) Handle( w http.ResponseWriter, r *http.Request, i *GetInputer, ) (any, error)
Handle processes the get endpoint.
Parameters:
- w: The response writer.
- r: The request.
- i: The db.
Returns:
- any: The endpoint output.
- error: An error if the request fails.
func (*GetHandler[Entity]) WithBeforeCallback ¶
func (h *GetHandler[Entity]) WithBeforeCallback( beforeCallback BeforeGetCallback, ) *GetHandler[Entity]
WithBeforeCallback returns a new get handler with the before callback.
Parameters:
- beforeCallback: The function that runs before the get operation.
Returns:
- *GetHandler: The new get handler.
func (*GetHandler[Entity]) WithEntityFactoryFn ¶
func (h *GetHandler[Entity]) WithEntityFactoryFn( entityFactoryFn db.GetterFactoryFn[Entity], ) *GetHandler[Entity]
WithEntityFactoryFn returns a new get handler with the entity factory function.
Parameters:
- entityFactoryFn: The function that creates a new entity.
Returns:
- *GetHandler: The new get handler.
func (*GetHandler[Entity]) WithGetInvokeFn ¶
func (h *GetHandler[Entity]) WithGetInvokeFn( getInvokeFn GetInvokeFn[Entity], ) *GetHandler[Entity]
WithGetInvokeFn returns a new get handler with the get invoke function.
Parameters:
- getInvokeFn: The function that invokes the get endpoint.
Returns:
- *GetHandler: The new get handler.
func (*GetHandler[Entity]) WithParseInputFn ¶
func (h *GetHandler[Entity]) WithParseInputFn( parseInputFn func(input *GetInputer) (*ParsedGetEndpointInput, error), ) *GetHandler[Entity]
WithParseInputFn returns a new get handler with the parse input function.
Parameters:
- parseInputFn: The function that parses the db.
Returns:
- *GetHandler: The new get handler.
func (*GetHandler[Entity]) WithToOutputFn ¶
func (h *GetHandler[Entity]) WithToOutputFn( toOutputFn ToGetOutputFn[Entity], ) *GetHandler[Entity]
WithToOutputFn returns a new get handler with the to output function.
Parameters:
- toOutputFn: The function that converts the entities to the endpoint output.
Returns:
- *GetHandler: The new get handler.
type GetInputer ¶
type GetInvokeFn ¶
type GetInvokeFn[Entity database.Getter] func( ctx context.Context, parsedInput *ParsedGetEndpointInput, entityFactoryFn db.GetterFactoryFn[Entity], ) ([]Entity, int, error)
GetInvokeFn is the function that invokes the get endpoint.
type GetOutputer ¶
type ParsedDeleteEndpointInput ¶
type ParsedDeleteEndpointInput struct {
Selectors db.Selectors
DeleteOpts *db.DeleteOptions
}
ParsedDeleteEndpointInput represents a parsed delete endpoint db.
func ParseDeleteInput ¶
func ParseDeleteInput( apiToDBFields inpututil.APIToDBFields, selectors apidb.APISelectors, orders apidb.Orders, limit int, ) (*ParsedDeleteEndpointInput, error)
ParseDeleteInput translates API delete input into DB delete db.
Parameters:
- apiToDBFields: A map translating API field names to their corresponding database field definitions.
- selectors: A slice of API-level selectors.
- orders: A slice of API-level orders.
- limit: The maximum number of entities to delete.
Returns:
- *ParsedDeleteEndpointInput: A pointer to the parsed delete endpoint db.
- error: An error if the input is invalid.
type ParsedGetEndpointInput ¶
type ParsedGetEndpointInput struct {
Selectors db.Selectors
Orders []db.Order
Page *db.Page
Count bool
}
ParsedGetEndpointInput represents a parsed get endpoint db.
func ParseGetInput ¶
func ParseGetInput( apiToDBFields inpututil.APIToDBFields, selectors apidb.APISelectors, orders apidb.Orders, inputPage *apidb.Page, maxPage int, count bool, ) (*ParsedGetEndpointInput, error)
ParseGetInput translates API parameters to DB parameters.
Parameters:
- apiToDBFields: A map translating API field names to their corresponding database field definitions.
- selectors: A slice of API-level selectors.
- orders: A slice of API-level orders.
- inputPage: A pointer to the input page.
- maxPage: The maximum page size.
- count: A boolean indicating whether to return the count.
Returns:
- *ParsedGetEndpointInput: A pointer to the parsed get endpoint db.
- error: An error if the input is invalid.
type ParsedUpdateEndpointInput ¶
ParsedUpdateEndpointInput represents a parsed update endpoint db.
func ParseUpdateInput ¶
func ParseUpdateInput( apiToDBFields inpututil.APIToDBFields, selectors apidb.APISelectors, updates apidb.APIUpdates, upsert bool, ) (*ParsedUpdateEndpointInput, error)
ParseUpdateInput translates API update input into DB update db.
Parameters:
- apiToDBFields: A map translating API field names to their corresponding database field definitions.
- selectors: A slice of API-level selectors.
- updates: A map of API-level updates.
- upsert: A boolean indicating whether to upsert.
Returns:
- *ParsedUpdateEndpointInput: A pointer to the parsed update endpoint db.
- error: An error if the input is invalid.
type ToCreateOutputFn ¶
type ToCreateOutputFn[Entity database.Mutator] func( entity Entity, ) (CreateOutputer[Entity], error)
ToCreateOutputFn is the function that converts the entity to the endpoint output.
type ToDeleteOutputFn ¶
type ToDeleteOutputFn func(count int64) (DeleteOutputer, error)
DeleteInvokeFn is the function that invokes the delete endpoint.
type ToGetOutputFn ¶
type ToGetOutputFn[Entity database.Getter] func( entities []Entity, count int, ) (GetOutputer[Entity], error)
ToGetOutputFn is the function that converts the entities to the endpoint output.
type ToUpdateOutputFn ¶
type ToUpdateOutputFn func(count int64) (UpdateOutputer, error)
UpdateInvokeFn is the function that invokes the update endpoint.
type UpdateEntityFactoryFn ¶
UpdateEntityFactoryFn is the function that creates a new entity.
type UpdateHandler ¶
UpdateHandler is the handler implementation for the update endpoint.
func NewUpdateHandler ¶
func NewUpdateHandler[Entity database.Mutator]( parseInputFn func( input *UpdateInputer, ) (*ParsedUpdateEndpointInput, error), updateInvokeFn UpdateInvokeFn[Entity], toOutputFn ToUpdateOutputFn, entityFactoryFn UpdateEntityFactoryFn[Entity], beforeCallback BeforeUpdateCallback[Entity], ) *UpdateHandler[Entity]
NewUpdateHandler creates a new update handler.
Parameters:
- parseInputFn: The function that parses the db.
- updateInvokeFn: The function that invokes the update endpoint.
- toOutputFn: The function that converts the entities to the endpoint output.
- entityFactoryFn: The function that creates a new entity.
- beforeCallback: The optional function that runs before the update operation.
Returns:
- *UpdateHandler: The new update handler.
func (*UpdateHandler[Entity]) Handle ¶
func (h *UpdateHandler[Entity]) Handle( w http.ResponseWriter, r *http.Request, i *UpdateInputer, ) (any, error)
Handle processes the update endpoint.
Parameters:
- w: The response writer.
- r: The request.
- i: The db.
Returns:
- any: The endpoint output.
- error: An error if the request fails.
func (*UpdateHandler[Entity]) WithBeforeUpdateCallback ¶
func (h *UpdateHandler[Entity]) WithBeforeUpdateCallback( beforeCallback BeforeUpdateCallback[Entity], ) *UpdateHandler[Entity]
WithBeforeUpdateCallback returns a new update handler with the before update callback.
Parameters:
- beforeCallback: The function that runs before the update operation.
Returns:
- *UpdateHandler: The new update handler.
func (*UpdateHandler[Entity]) WithEntityFactoryFn ¶
func (h *UpdateHandler[Entity]) WithEntityFactoryFn( entityFactoryFn UpdateEntityFactoryFn[Entity], ) *UpdateHandler[Entity]
WithEntityFactoryFn returns a new update handler with the entity factory function.
Parameters:
- entityFactoryFn: The function that creates a new entity.
Returns:
- *UpdateHandler: The new update handler.
func (*UpdateHandler[Entity]) WithParseInputFn ¶
func (h *UpdateHandler[Entity]) WithParseInputFn( parseInputFn func(input *UpdateInputer, ) (*ParsedUpdateEndpointInput, error), ) *UpdateHandler[Entity]
WithParseInputFn returns a new update handler with the parse input function.
Parameters:
- parseInputFn: The function that parses the db.
Returns:
- *UpdateHandler: The new update handler.
func (*UpdateHandler[Entity]) WithToOutputFn ¶
func (h *UpdateHandler[Entity]) WithToOutputFn( toOutputFn ToUpdateOutputFn, ) *UpdateHandler[Entity]
WithToOutputFn returns a new update handler with the to output function.
Parameters:
- toOutputFn: The function that converts the entities to the endpoint output.
Returns:
- *UpdateHandler: The new update handler.
func (*UpdateHandler[Entity]) WithUpdateInvokeFn ¶
func (h *UpdateHandler[Entity]) WithUpdateInvokeFn( updateInvokeFn UpdateInvokeFn[Entity], ) *UpdateHandler[Entity]
WithUpdateInvokeFn returns a new update handler with the update invoke function.
Parameters:
- updateInvokeFn: The function that invokes the update endpoint.
Returns:
- *UpdateHandler: The new update handler.
type UpdateInputer ¶
type UpdateInputer interface {
GetSelectors() apidb.APISelectors
GetUpdates() apidb.APIUpdates
GetUpsert() bool
}
type UpdateInvokeFn ¶
type UpdateInvokeFn[Entity database.Mutator] func( ctx context.Context, parsedInput *ParsedUpdateEndpointInput, updater Entity, ) (int64, error)
UpdateInvokeFn is the function that invokes the update endpoint.
type UpdateOutputer ¶
type UpdateOutputer interface {
SetCount(count int64)
}