api

package
v0.0.0-...-14f90b6 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2023 License: MIT Imports: 30 Imported by: 0

Documentation

Index

Constants

View Source
const (
	InteractivesCreatePermission string = "interactives:create"
	InteractivesReadPermission   string = "interactives:read"
	InteractivesUpdatePermission string = "interactives:update"
	InteractivesDeletePermission string = "interactives:delete"
)
View Source
const (
	UpdateFieldKey = "interactive"
	FileFieldKey   = "file"
)
View Source
const (
	MaxCollisions = 10
)

Variables

View Source
var (
	WantOnlyOneAttachmentWithMetadata = func(r *http.Request) error {
		numOfAttachments, update := len(r.MultipartForm.File), r.FormValue(UpdateFieldKey)
		if numOfAttachments == 1 && update != "" {
			return nil
		}
		return errors.New("expecting one attachment with metadata")
	}
	WantAtleastMaxOneAttachmentAndOrMetadata = func(r *http.Request) error {
		numOfAttachments, update := len(r.MultipartForm.File), r.FormValue(UpdateFieldKey)
		if numOfAttachments == 1 || update != "" {
			return nil
		}
		return errors.New("no attachment (max one) or metadata present")
	}
)
View Source
var (
	ErrInvalidBody           = errors.New("body has invalid format")
	ErrCantDeletePublishedIn = errors.New("cannot delete a published interactive")
)

Functions

This section is empty.

Types

type API

type API struct {
	Router *mux.Router
	// contains filtered or unexported fields
}

func Setup

func Setup(ctx context.Context,
	cfg *config.Config,
	r *mux.Router,
	auth authorisation.Middleware,
	mongoDB MongoServer,
	kafkaProducer kafka.IProducer,
	s3 S3Interface,
	filesService FilesService,
	newUUID data.Generator,
	newResourceID data.Generator,
	newSlug data.Generator,
	respond *responder.Responder) *API

Setup creates the API struct and its endpoints with corresponding handlers

func (*API) Close

func (*API) Close(ctx context.Context) error

Close is called during graceful shutdown to give the API an opportunity to perform any required disposal task

func (*API) DeleteInteractivesHandler

func (api *API) DeleteInteractivesHandler(w http.ResponseWriter, r *http.Request)

func (*API) GetInteractive

func (api *API) GetInteractive(ctx context.Context, req *http.Request) (*models.Interactive, int, error)

func (*API) GetInteractiveHandler

func (api *API) GetInteractiveHandler(w http.ResponseWriter, r *http.Request)

func (*API) ListInteractivesHandler

func (api *API) ListInteractivesHandler(w http.ResponseWriter, req *http.Request)

func (*API) PatchInteractiveHandler

func (api *API) PatchInteractiveHandler(w http.ResponseWriter, r *http.Request)

func (*API) PublishCollectionHandler

func (api *API) PublishCollectionHandler(w http.ResponseWriter, r *http.Request)

dedicated publish collection as multiple interactives can be a part of a single collection

func (*API) UpdateInteractiveHandler

func (api *API) UpdateInteractiveHandler(w http.ResponseWriter, r *http.Request)

update rules if published - allow only file updates if unpublished - allow both file + metadata

func (*API) UploadInteractivesHandler

func (api *API) UploadInteractivesHandler(w http.ResponseWriter, r *http.Request)

type AuthHandler

type AuthHandler interface {
	Require(permission string, handler http.HandlerFunc) http.HandlerFunc
}

AuthHandler interface for adding auth to endpoints

type FilesService

type FilesService interface {
	SetCollectionID(ctx context.Context, file, collectionID string) error
	Checker(ctx context.Context, state *healthcheck.CheckState) error
}

type FormDataRequest

type FormDataRequest struct {
	Name        string
	Interactive *models.Interactive

	TmpFileName string
	// contains filtered or unexported fields
}

type FormDataValidator

type FormDataValidator func(*http.Request) error

type MongoServer

type MongoServer interface {
	Close(ctx context.Context) error
	Checker(ctx context.Context, state *healthcheck.CheckState) (err error)
	UpsertInteractive(ctx context.Context, id string, vis *models.Interactive) (err error)
	GetInteractive(ctx context.Context, id string) (*models.Interactive, error)
	ListInteractives(ctx context.Context, filter *models.Filter) ([]*models.Interactive, error)
	PatchInteractive(context.Context, interactives.PatchAttribute, *models.Interactive) error
}

type S3Interface

type S3Interface interface {
	Upload(input *s3manager.UploadInput, options ...func(*s3manager.Uploader)) (*s3manager.UploadOutput, error)
	ValidateBucket() error
	Checker(ctx context.Context, state *healthcheck.CheckState) error
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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