classsvc

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2017 License: GPL-3.0 Imports: 20 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUnauthenticated = svcerror.New(codes.Unauthenticated, "token invalid or not found")
	ErrNotFound        = svcerror.New(codes.NotFound, "resource not found or user is not allowed to access it")
	ErrForbidden       = svcerror.New(codes.Forbidden, "user is not allowed to perform action")
	ErrMustSetOwner    = svcerror.New(codes.MustSetOwner, "cannot demote self from owner unless new owner is set")
	ErrUserEnrolled    = svcerror.New(codes.UserEnrolled, "user is already enrolled in class")
)
View Source
var (
	ErrBadRequest = svcerror.New(codes.BadRequest, "the request is malformed or invalid")
)

Functions

func DecodeCreateClassRequest

func DecodeCreateClassRequest(_ context.Context, r *http.Request) (interface{}, error)

func DecodeCreateClassResponse

func DecodeCreateClassResponse(_ context.Context, resp *http.Response) (interface{}, error)

func DecodeDeleteClassRequest

func DecodeDeleteClassRequest(_ context.Context, r *http.Request) (interface{}, error)

func DecodeDeleteClassResponse

func DecodeDeleteClassResponse(_ context.Context, resp *http.Response) (interface{}, error)

func DecodeGetClassRequest

func DecodeGetClassRequest(_ context.Context, r *http.Request) (interface{}, error)

func DecodeGetClassResponse

func DecodeGetClassResponse(_ context.Context, resp *http.Response) (interface{}, error)

func DecodeJoinClassRequest

func DecodeJoinClassRequest(_ context.Context, r *http.Request) (interface{}, error)

func DecodeJoinClassResponse

func DecodeJoinClassResponse(_ context.Context, resp *http.Response) (interface{}, error)

func DecodeLeaveClassRequest

func DecodeLeaveClassRequest(_ context.Context, r *http.Request) (interface{}, error)

func DecodeLeaveClassResponse

func DecodeLeaveClassResponse(_ context.Context, resp *http.Response) (interface{}, error)

func DecodeListClassesRequest

func DecodeListClassesRequest(_ context.Context, _ *http.Request) (interface{}, error)

func DecodeListClassesResponse

func DecodeListClassesResponse(_ context.Context, resp *http.Response) (interface{}, error)

func DecodeListMembersRequest

func DecodeListMembersRequest(_ context.Context, r *http.Request) (interface{}, error)

func DecodeListMembersResponse

func DecodeListMembersResponse(_ context.Context, resp *http.Response) (interface{}, error)

func DecodeSetRoleRequest

func DecodeSetRoleRequest(_ context.Context, r *http.Request) (interface{}, error)

func DecodeSetRoleResponse

func DecodeSetRoleResponse(_ context.Context, resp *http.Response) (interface{}, error)

func DecodeUpdateClassRequest

func DecodeUpdateClassRequest(_ context.Context, r *http.Request) (interface{}, error)

func DecodeUpdateClassResponse

func DecodeUpdateClassResponse(_ context.Context, resp *http.Response) (interface{}, error)

func EncodeCreateClassRequest

func EncodeCreateClassRequest(ctx context.Context, req *http.Request, request interface{}) error

func EncodeDeleteClassRequest

func EncodeDeleteClassRequest(ctx context.Context, req *http.Request, request interface{}) error

func EncodeError

func EncodeError(_ context.Context, err error, w http.ResponseWriter)

func EncodeGetClassRequest

func EncodeGetClassRequest(ctx context.Context, req *http.Request, request interface{}) error

func EncodeJoinClassRequest

func EncodeJoinClassRequest(ctx context.Context, req *http.Request, request interface{}) error

func EncodeLeaveClassRequest

func EncodeLeaveClassRequest(ctx context.Context, req *http.Request, request interface{}) error

func EncodeListClassesRequest

func EncodeListClassesRequest(ctx context.Context, req *http.Request, request interface{}) error

func EncodeListMembersRequest

func EncodeListMembersRequest(ctx context.Context, req *http.Request, request interface{}) error

func EncodeRequest

func EncodeRequest(_ context.Context, req *http.Request, request interface{}) error

EncodeRequest likewise JSON-Encodes the request to the HTTP request body. Don't use it directly as a transport/http.Client EncodeRequestFunc: profilesvc endpoints require mutating the HTTP method and request path.

func EncodeResponse

func EncodeResponse(ctx context.Context, w http.ResponseWriter, response interface{}) error

EncodeResponse is the common method to Encode all response types to the client. I chose to do it this way because, since we're using JSON, there's no reason to provide anything more specific. It's certainly possible to specialize on a per-response (per-method) basis.

func EncodeSetRoleRequest

func EncodeSetRoleRequest(ctx context.Context, req *http.Request, request interface{}) error

func EncodeUpdateClassRequest

func EncodeUpdateClassRequest(ctx context.Context, req *http.Request, request interface{}) error

func MakeCreateClassEndpoint

func MakeCreateClassEndpoint(s Service) endpoint.Endpoint

func MakeDeleteClassEndpoint

func MakeDeleteClassEndpoint(s Service) endpoint.Endpoint

func MakeGetClassEndpoint

func MakeGetClassEndpoint(s Service) endpoint.Endpoint

func MakeHTTPHandler

func MakeHTTPHandler(s Service, logger log.Logger, client *sdk.Client) http.Handler

func MakeJoinClassEndpoint

func MakeJoinClassEndpoint(s Service) endpoint.Endpoint

func MakeLeaveClassEndpoint

func MakeLeaveClassEndpoint(s Service) endpoint.Endpoint

func MakeListClassesEndpoint

func MakeListClassesEndpoint(s Service) endpoint.Endpoint

func MakeListMembersEndpoint

func MakeListMembersEndpoint(s Service) endpoint.Endpoint

func MakeSetRoleEndpoint

func MakeSetRoleEndpoint(s Service) endpoint.Endpoint

func MakeUpdateClassEndpoint

func MakeUpdateClassEndpoint(s Service) endpoint.Endpoint

Types

type Endpoints

type Endpoints struct {
	ListClassesEndpoint endpoint.Endpoint
	GetClassEndpoint    endpoint.Endpoint
	CreateClassEndpoint endpoint.Endpoint
	UpdateClassEndpoint endpoint.Endpoint
	DeleteClassEndpoint endpoint.Endpoint
	JoinClassEndpoint   endpoint.Endpoint
	SetRoleEndpoint     endpoint.Endpoint
	LeaveClassEndpoint  endpoint.Endpoint
	ListMembersEndpoint endpoint.Endpoint
}

Endpoints collects all of the endpoints that compose a class service. It's meant to be used as a helper struct, to collect all of the endpoints into a single parameter.

In a server, it's useful for functions that need to operate on a per-endpoint basis. For example, you might pass an Endpoints to a function that produces an http.Handler, with each method (endpoint) wired up to a specific path. (It is probably a mistake in design to invoke the Service methods on the Endpoints struct in a server.)

In a client, it's useful to collect individually constructed endpoints into a single type that implements the Service interface. For example, you might construct individual endpoints using transport/http.NewClient, combine them into an Endpoints, and return it to the caller as a Service.

func MakeClientEndpoints

func MakeClientEndpoints(instance string) (Endpoints, error)

MakeClientEndpoints returns an Endpoints struct where each endpoint invokes the corresponding method on the remote instance, via a transport/http.Client. Useful in a classsvc client.

func MakeServerEndpoints

func MakeServerEndpoints(s Service) Endpoints

func (Endpoints) CreateClass

func (e Endpoints) CreateClass(ctx context.Context, name string) (uuid.UUID, error)

func (Endpoints) DeleteClass

func (e Endpoints) DeleteClass(ctx context.Context, classID uuid.UUID) error

func (Endpoints) GetClass

func (e Endpoints) GetClass(ctx context.Context, classID uuid.UUID) (*models.Class, error)

func (Endpoints) JoinClass

func (e Endpoints) JoinClass(ctx context.Context, classID uuid.UUID) error

func (Endpoints) LeaveClass

func (e Endpoints) LeaveClass(ctx context.Context, classID uuid.UUID, userID uuid.UUID) error

func (Endpoints) ListClasses

func (e Endpoints) ListClasses(ctx context.Context) ([]uuid.UUID, error)

func (Endpoints) ListMembers

func (e Endpoints) ListMembers(ctx context.Context, classID uuid.UUID) ([]*models.Member, error)

func (Endpoints) SetRole

func (e Endpoints) SetRole(ctx context.Context, userID uuid.UUID, classID uuid.UUID, role models.UserRole) error

func (Endpoints) UpdateClass

func (e Endpoints) UpdateClass(ctx context.Context, classID uuid.UUID, name string, currentUnit uuid.UUID) error

type Service

type Service interface {
	// ListClasses gets all classes the current user is enrolled in.
	ListClasses(ctx context.Context) ([]uuid.UUID, error)
	// GetClass gets details for a specific class.
	GetClass(ctx context.Context, id uuid.UUID) (*models.Class, error)
	// CreateClass creates a class and enrolls the current user in it as an administrator.
	CreateClass(ctx context.Context, name string) (uuid.UUID, error)
	// UpdateClass updates a class.
	UpdateClass(ctx context.Context, id uuid.UUID, name string, currentUnit uuid.UUID) error
	// DeleteClass deactivates a class.
	DeleteClass(ctx context.Context, id uuid.UUID) error
	// JoinClass enrolls the current user in a class.
	JoinClass(ctx context.Context, class uuid.UUID) error
	// LeaveClass causes a user to be un-enrolled from a class.
	// If user is not `uuid.Nil`, then LeaveClass removes the other user, requiring the current user to have elevated permissions.
	LeaveClass(ctx context.Context, user uuid.UUID, class uuid.UUID) error
	// SetRole sets the role of a user in a class.
	// The current user must have a higher role than the target user.
	SetRole(ctx context.Context, user uuid.UUID, class uuid.UUID, role models.UserRole) error
	// ListMembers lists all members of a class and their role.
	ListMembers(ctx context.Context, classId uuid.UUID) ([]*models.Member, error)
}

func NewPostgres

func NewPostgres(db *sql.DB) Service

Jump to

Keyboard shortcuts

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