Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CrudOptions ¶
type CrudOptions struct {
// IDParameterName is the name of the GET parameter which is used
// for getting and deleting documents
IDParameterName string
// ListEndpoint is the http-endpoint-name for list queries
// If == nil there will be no list-enpoint
ListEndpoint *string
ListPreprocess func(context.Context) error
ListMiddleware uhttp.Middleware
ListRequiredGet uhttp.R
ListOptionalGet uhttp.R
// GetEndpoint is the http-endpoint-name for get queries
// If == nil there will be no get-enpoint
GetEndpoint *string
GetPreprocess func(context.Context) error
GetMiddleware uhttp.Middleware
GetRequiredGet uhttp.R
GetOptionalGet uhttp.R
// CreateEndpoint is the http-endpoint-name for create queries
// If == nil there will be no create-enpoint
CreateEndpoint *string
CreatePreprocess func(context.Context) error
CreateMiddleware uhttp.Middleware
CreateRequiredGet uhttp.R
CreateOptionalGet uhttp.R
// UpdateEndpoint is the http-endpoint-name for update queries
// If == nil there will be no update-enpoint
UpdateEndpoint *string
UpdatePreprocess func(context.Context) error
UpdateMiddleware uhttp.Middleware
UpdateRequiredGet uhttp.R
UpdateOptionalGet uhttp.R
// DeleteEndpoint is the http-endpoint-name for delete queries
// If == nil there will be no delete-enpoint
DeleteEndpoint *string
DeletePreprocess func(context.Context) error
DeleteMiddleware uhttp.Middleware
DeleteRequiredGet uhttp.R
DeleteOptionalGet uhttp.R
// ModelService will be called upon for all database interactions
ModelService ModelService
// Model will be used to parse and validate models given to create/update handlers
Model WithID
}
func (CrudOptions) CreateEndpoints ¶
func (o CrudOptions) CreateEndpoints(u *uhttp.UHTTP) error
CreateEndpoints adds all handlers configured in CrudOptions using the uhttp-framework
type ModelService ¶
type ModelService interface {
// Validate should validate the model which is created/updated
// - called from the createHandler, before it calls service.Create
// - called from the updateHandler, before it calls service.Update
Validate(interface{}) bool
// Get retrieves a document by its ID (typically a string or ObjectID etc.)
// If limitToUser is true the service should only return documents which belong to the user
Get(ID string, ctx context.Context) (interface{}, error)
// List retrieves all documents which this user has access to
// If limitToUser is true the service should only return documents which belong to the user
// ctx will contain the request-context. This way we can pass on filters from the reuqest
// into the service
List(ctx context.Context) (interface{}, error)
// Create creates a document in the database and returns the new document
// If permissions are implemented, the service should make this created document belong to the
// user passed into this method
Create(obj interface{}, ctx context.Context) (interface{}, error)
// Update updates a document. It is up to the implementer to get the ID-property, etc.
// It returns the updated document
// If limitToUser is true the service should check if this user is allowed to modify this document
Update(obj interface{}, ctx context.Context) (interface{}, error)
// Delete deletes a document by its ID (typically a string or ObjectID etc.)
// If limitToUser is true the service should check if this user is allowed to delete this document
Delete(ID string, ctx context.Context) error
}
ModelService is an interface which all CRUD-http-handlers will use
Click to show internal directories.
Click to hide internal directories.