crud

package
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2021 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotCreated = leikari.Errorln("", "entity not created")
	ErrNotFound   = repository.ErrNotFound
	ErrNotUpdated = leikari.Errorln("", "entity not updated")
	ErrNotDeleted = leikari.Errorln("", "entity not deleted")
)

Functions

func HandleCreate

func HandleCreate(unmarshal func([]byte) (interface{}, error)) func(CrudRef) func(r route.Request) route.Response

func HandleDelete

func HandleDelete(ref CrudRef) func(r route.Request) route.Response

func HandlePostQuery

func HandlePostQuery(ref CrudRef) func(r route.Request) route.Response

func HandleQuery

func HandleQuery(ref CrudRef) func(r route.Request) route.Response

func HandleRead

func HandleRead(ref CrudRef) func(r route.Request) route.Response

func HandleUnmarshal

func HandleUnmarshal(b []byte) (interface{}, error)

func HandleUpdate

func HandleUpdate(unmarshal func([]byte) (interface{}, error)) func(CrudRef) func(r route.Request) route.Response

Types

type Client

type Client interface {
	Create(interface{}) (interface{}, error)
	CreateContext(context.Context, interface{}) (interface{}, error)

	Read(string) (interface{}, error)
	ReadContext(context.Context, string) (interface{}, error)

	Update(string, interface{}) (interface{}, error)
	UpdateContext(context.Context, string, interface{}) (interface{}, error)

	Delete(string) (interface{}, error)
	DeleteContext(context.Context, string) (interface{}, error)

	List(query.Query) (*query.QueryResult, error)
	ListContext(context.Context, query.Query) (*query.QueryResult, error)
}

func CrudClient

func CrudClient(baseurl string) (Client, error)

func NewCrudClient

func NewCrudClient(client *http.Client, baseurl string) (Client, error)

type CreateCommand

type CreateCommand struct {
	Entity interface{}
}

type CreateFunc

type CreateFunc func(leikari.ActorContext, interface{}) (string, interface{}, error)

type CreateHandler

type CreateHandler interface {
	Create(leikari.ActorContext, CreateCommand) (*CreatedEvent, error)
}

type CreateRouteHandler

type CreateRouteHandler interface {
	HandleCreate(CrudRef) func(route.Request) route.Response
}

type CreatedEvent

type CreatedEvent struct {
	Id        string      `json:"id"`
	Entity    interface{} `json:"entity"`
	Timestamp time.Time   `json:"timestamp,omitempty"`
	Took      int64       `json:"millis,omitempty"`
}

type CrudEncoding

type CrudEncoding interface {
}

type CrudHandler

type CrudHandler struct {
	OnCreate    CreateFunc
	OnRead      ReadFunc
	OnUpdate    UpdateFunc
	OnDelete    DeleteFunc
	OnQuery     QueryFunc
	OnReceive   func(leikari.ActorContext, leikari.Message)
	OnStart     func(leikari.ActorContext) error
	OnStop      func(leikari.ActorContext) error
	OnUnmarshal func([]byte) (interface{}, error)
	Sync        bool
}

func (*CrudHandler) AsyncActor

func (a *CrudHandler) AsyncActor() bool

func (*CrudHandler) Create

func (*CrudHandler) Delete

func (*CrudHandler) HandleUnmarshal

func (a *CrudHandler) HandleUnmarshal(data []byte) (interface{}, error)

func (*CrudHandler) PostStop

func (a *CrudHandler) PostStop(ctx leikari.ActorContext) error

func (*CrudHandler) PreStart

func (a *CrudHandler) PreStart(ctx leikari.ActorContext) error

func (*CrudHandler) Query

func (*CrudHandler) Read

func (*CrudHandler) Receive

func (a *CrudHandler) Receive(ctx leikari.ActorContext, msg leikari.Message)

func (*CrudHandler) Update

type CrudRef

type CrudRef interface {
	leikari.Ref
	Create(interface{}) (*CreatedEvent, error)
	CreateContext(context.Context, interface{}) (*CreatedEvent, error)

	Read(string) (*ReadEvent, error)
	ReadContext(context.Context, string) (*ReadEvent, error)

	Update(string, interface{}) (*UpdatedEvent, error)
	UpdateContext(context.Context, string, interface{}) (*UpdatedEvent, error)

	Delete(string) (*DeletedEvent, error)
	DeleteContext(context.Context, string) (*DeletedEvent, error)

	List(query.Query) (*query.QueryResult, error)
	ListContext(context.Context, query.Query) (*query.QueryResult, error)
}

func CrudService

func CrudService(system leikari.ActorExecutor, handler interface{}, name string, opts ...leikari.Option) (CrudRef, route.Route, error)

type DeleteCommand

type DeleteCommand struct {
	Id string
}

type DeleteFunc

type DeleteFunc func(leikari.ActorContext, string) (interface{}, error)

type DeleteHandler

type DeleteHandler interface {
	Delete(leikari.ActorContext, DeleteCommand) (*DeletedEvent, error)
}

type DeleteRouteHandler

type DeleteRouteHandler interface {
	HandleDelete(CrudRef) func(route.Request) route.Response
}

type DeletedEvent

type DeletedEvent struct {
	Id        string      `json:"id"`
	Entity    interface{} `json:"entity"`
	Timestamp time.Time   `json:"timestamp"`
	Took      int64       `json:"millis,omitempty"`
}

type PostQueryRouteHandler

type PostQueryRouteHandler interface {
	HandlePostQuery(CrudRef) func(route.Request) route.Response
}

type QueryFunc

type QueryFunc func(leikari.ActorContext, query.Query) (*query.QueryResult, error)

type QueryRouteHandler

type QueryRouteHandler interface {
	HandleQuery(CrudRef) func(route.Request) route.Response
}

type ReadCommand

type ReadCommand struct {
	Id string
}

type ReadEvent

type ReadEvent struct {
	Id        string      `json:"id"`
	Entity    interface{} `json:"entity"`
	Timestamp time.Time   `json:"timestamp,omitempty"`
	Took      int64       `json:"millis,omitempty"`
}

type ReadFunc

type ReadFunc func(leikari.ActorContext, string) (interface{}, error)

type ReadHandler

type ReadHandler interface {
	Read(leikari.ActorContext, ReadCommand) (*ReadEvent, error)
}

type ReadRouteHandler

type ReadRouteHandler interface {
	HandleRead(CrudRef) func(route.Request) route.Response
}

type UnmarshalHandler

type UnmarshalHandler interface {
	HandleUnmarshal([]byte) (interface{}, error)
}

type UpdateCommand

type UpdateCommand struct {
	Id     string
	Entity interface{}
}

type UpdateFunc

type UpdateFunc func(leikari.ActorContext, string, interface{}) error

type UpdateHandler

type UpdateHandler interface {
	Update(leikari.ActorContext, UpdateCommand) (*UpdatedEvent, error)
}

type UpdateRouteHandler

type UpdateRouteHandler interface {
	HandleUpdate(CrudRef) func(route.Request) route.Response
}

type UpdatedEvent

type UpdatedEvent struct {
	Id        string      `json:"id"`
	Entity    interface{} `json:"entity"`
	Timestamp time.Time   `json:"timestamp,omitempty"`
	Took      int64       `json:"millis,omitempty"`
}

Jump to

Keyboard shortcuts

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