uhttpcrud

package module
v1.0.37 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2021 License: MIT Imports: 6 Imported by: 0

README

Build Status GoDoc codecov

uhttpcrud

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
	ListPermission       *uauth.Permission
	ListOthersPermission *uauth.Permission
	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
	GetPermission       *uauth.Permission
	GetOthersPermission *uauth.Permission
	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
	CreatePermission       *uauth.Permission
	CreateOthersPermission *uauth.Permission
	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
	UpdatePermission       *uauth.Permission
	UpdateOthersPermission *uauth.Permission
	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
	DeletePermission       *uauth.Permission
	DeleteOthersPermission *uauth.Permission
	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, limitToUser bool, 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(limitToUser bool, 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{}, limitToUser bool, 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, limitToUser bool, ctx context.Context) error
}

ModelService is an interface which all CRUD-http-handlers will use

type WithID

type WithID interface {
	// Returns the ID of this struct (typically a string or ObjectID, etc.)
	GetID() (string, error)
}

WithID makes sure the struct in question has a gettable ID property for DB-operations

Jump to

Keyboard shortcuts

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