classsvc

package
v0.1.10 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUnauthorized = errors.New("token invalid or not found")
	ErrNotFound     = errors.New("resource not found or user is not allowed to access it")
	ErrForbidden    = errors.New("user is not allowed to perform action")
	ErrMustSetOwner = errors.New("cannot demote self from owner unless new owner is set")
	ErrUserEnrolled = errors.New("user is already enrolled in class")
	ErrInternal     = errors.New("internal server error")
)
View Source
var (
	ErrBadRequest = errors.New("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 DecodeGetMemberRequest added in v0.1.0

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

func DecodeGetMemberResponse added in v0.1.0

func DecodeGetMemberResponse(_ 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 EncodeGetClassRequest

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

func EncodeGetMemberRequest added in v0.1.0

func EncodeGetMemberRequest(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 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 MakeGetMemberEndpoint added in v0.1.0

func MakeGetMemberEndpoint(s Service) endpoint.Endpoint

func MakeHTTPHandler

func MakeHTTPHandler(s Service, introspection oauth2.Introspector, logger log.Logger) 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
	GetMemberEndpoint   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) GetMember added in v0.1.0

func (e Endpoints) GetMember(ctx context.Context, classID, userID uuid.UUID) (*models.Member, 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, userID *uuid.UUID, classID 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, classID, userID 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 Middleware added in v0.1.0

type Middleware func(Service) Service

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, classID 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, classID uuid.UUID, name *string, currentUnit *uuid.UUID) error
	// DeleteClass deactivates a class.
	DeleteClass(ctx context.Context, classID uuid.UUID) error
	// JoinClass enrolls the current user in a class.
	JoinClass(ctx context.Context, classID uuid.UUID) error
	// LeaveClass causes a user to be un-enrolled from a class.
	// If user is not nil, then LeaveClass removes the other user, requiring the current user to have elevated permissions.
	LeaveClass(ctx context.Context, userID *uuid.UUID, classID 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, classID uuid.UUID, userID 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)
	// GetMember gets a member of a class.
	GetMember(ctx context.Context, classID, userID uuid.UUID) (member *models.Member, err error)
}

Service represents a Studiously class service.

func New added in v0.1.0

func New(db *sql.DB) Service

Jump to

Keyboard shortcuts

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