service

package
v2.2.6 Latest Latest
Warning

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

Go to latest
Published: May 16, 2023 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

This package implements most commonly used endpoint logic in RFC7644.

The services defined in this package are the entry point of this module. They should be called by client HTTP handler implementations to perform the heavy lifting.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Create

type Create interface {
	Do(ctx context.Context, req *CreateRequest) (resp *CreateResponse, err error)
}

Create resource service

func CreateService

func CreateService(resourceType *spec.ResourceType, database db.DB, filters []filter.ByResource) Create

Create returns a create resource service.

type CreateRequest

type CreateRequest struct {
	PayloadSource io.Reader // reader source to read resource payload from
}

Create resource request

type CreateResponse

type CreateResponse struct {
	Resource *prop.Resource // the created resource
}

Create resource response

type Delete

type Delete interface {
	Do(ctx context.Context, req *DeleteRequest) (resp *DeleteResponse, err error)
}

Delete resource service

func DeleteService

func DeleteService(config *spec.ServiceProviderConfig, database db.DB) Delete

DeleteService returns a delete resource service

type DeleteRequest

type DeleteRequest struct {
	ResourceID    string                             // id of the resource to be deleted
	MatchCriteria func(resource *prop.Resource) bool // extra criteria the resource has to meet in order to be deleted
}

Delete resource request

type DeleteResponse

type DeleteResponse struct {
	Deleted *prop.Resource // the resource that was deleted
}

Delete resource response

type Get

type Get interface {
	Do(ctx context.Context, req *GetRequest) (resp *GetResponse, err error)
}

Get resource resource

func GetService

func GetService(database db.DB) Get

GetService returns a get resource service.

type GetRequest

type GetRequest struct {
	ResourceID string           // id of the resource to get
	Projection *crud.Projection // field projection to be considered when fetching resource
}

Get resource request

type GetResponse

type GetResponse struct {
	Resource *prop.Resource // resource got from database
}

Get resource response

type Patch

type Patch interface {
	Do(ctx context.Context, req *PatchRequest) (resp *PatchResponse, err error)
}

Patch resource service

func PatchService

func PatchService(
	config *spec.ServiceProviderConfig,
	database db.DB,
	preFilters []filter.ByResource,
	postFilters []filter.ByResource,
) Patch

PatchService returns a patch resource service. preFilters will run after resource fetched from database and before resource is patched. postFilters will run after resource has been patched and before resource is saved back to database.

type PatchOperation

type PatchOperation struct {
	Op    string          `json:"op"`
	Path  string          `json:"path"`
	Value json.RawMessage `json:"value"`
}

Patch operation definition

func (*PatchOperation) ParseValue

func (o *PatchOperation) ParseValue(resource *prop.Resource) (interface{}, error)

type PatchPayload

type PatchPayload struct {
	Schemas    []string         `json:"schemas"`
	Operations []PatchOperation `json:"Operations"`
}

Patch payload definition

func (*PatchPayload) Validate

func (p *PatchPayload) Validate() error

type PatchRequest

type PatchRequest struct {
	ResourceID    string                             // id of the resource to patch
	MatchCriteria func(resource *prop.Resource) bool // extra criteria to meet for the resource to be patched
	PayloadSource io.Reader                          // source to read the patch payload from
}

Patch resource request

type PatchResponse

type PatchResponse struct {
	Patched  bool           // true if the resource was patched; false if the resource was not patched but there was no error
	Ref      *prop.Resource // reference resource (the before state)
	Resource *prop.Resource // patched resource (the after state)
}

Patch resource response

type Query

type Query interface {
	Do(ctx context.Context, req *QueryRequest) (resp *QueryResponse, err error)
}

Query resource service

func QueryService

func QueryService(config *spec.ServiceProviderConfig, database db.DB) Query

QueryService returns a query resource service. This service is only capable of performing querying on a single type of resource. This does not handle root query.

type QueryRequest

type QueryRequest struct {
	Filter     string
	Sort       *crud.Sort
	Pagination *crud.Pagination
	Projection *crud.Projection
}

Query resource request

func (*QueryRequest) ValidateAndDefault

func (q *QueryRequest) ValidateAndDefault() error

type QueryResponse

type QueryResponse struct {
	TotalResults int
	StartIndex   int
	ItemsPerPage int
	Resources    []json.Serializable
	Projection   *crud.Projection // included so that caller may render properly
}

Query resource response

type Replace

type Replace interface {
	Do(ctx context.Context, req *ReplaceRequest) (resp *ReplaceResponse, err error)
}

Replace resource service

func ReplaceService

func ReplaceService(
	config *spec.ServiceProviderConfig,
	resourceType *spec.ResourceType,
	database db.DB,
	filters []filter.ByResource,
) Replace

ReplaceService returns a replace service.

type ReplaceRequest

type ReplaceRequest struct {
	ResourceID    string                             // id of the resource to be replaced
	PayloadSource io.Reader                          // source to read replacement payload from
	MatchCriteria func(resource *prop.Resource) bool // extra criteria to meet in order to be replaced
}

Replace resource request

type ReplaceResponse

type ReplaceResponse struct {
	Replaced bool           // true if resource was replaced; false if resource was not replaced, but has no error
	Ref      *prop.Resource // reference resource (before state)
	Resource *prop.Resource // replaced resource (after state)
}

Replace resource response

Directories

Path Synopsis
This package defines filtering mechanism on resources, which consists the main extension point in services.
This package defines filtering mechanism on resources, which consists the main extension point in services.

Jump to

Keyboard shortcuts

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