document

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Feb 11, 2022 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CreateShelfCommand   = "cms.media.document.shelf.create"
	RemoveCommand        = "cms.media.document.shelf.remove_document"
	RenameCommand        = "cms.media.document.shelf.rename_document"
	MakeUniqueCommand    = "cms.media.document.shelf.make_document_unique"
	MakeNonUniqueCommand = "cms.media.document.shelf.make_document_non_unique"
	TagCommand           = "cms.media.document.shelf.tag_document"
	UntagCommand         = "cms.media.document.shelf.untag_document"
)

Shelf commands.

View Source
const (
	ShelfCreated          = "cms.media.document.shelf.created"
	DocumentAdded         = "cms.media.document.shelf.document_added"
	DocumentRemoved       = "cms.media.document.shelf.document_removed"
	DocumentReplaced      = "cms.media.document.shelf.document_replaced"
	DocumentRenamed       = "cms.media.document.shelf.document_renamed"
	DocumentMadeUnique    = "cms.media.document.shelf.document_made_unique"
	DocumentMadeNonUnique = "cms.media.document.shelf.document_made_non_unique"
	DocumentTagged        = "cms.media.document.shelf.document_tagged"
	DocumentUntagged      = "cms.media.document.shelf.document_untagged"
)

Shelf events

View Source
const Aggregate = "cms.media.document.shelf"

Aggregate is the name of the Document aggregate.

Variables

View Source
var (
	// ErrShelfAlreadyCreated is returned when creating a Shelf that was already created.
	ErrShelfAlreadyCreated = errors.New("shelf already created")

	// ErrShelfNotCreated is returned when trying to use a Shelf that wasn't created yet.
	ErrShelfNotCreated = errors.New("shelf not created")

	// ErrEmptyName is returned when providing a name that is empty or contains only whitespace.
	ErrEmptyName = errors.New("empty name")

	// ErrDuplicateUniqueName is returned when adding a Document to a Shelf with
	// an already taken UniqueName.
	ErrDuplicateUniqueName = errors.New("duplicate unique name")

	// ErrShelfNotFound is returned when a Shelf cannot be found in a Repository.
	ErrShelfNotFound = errors.New("shelf not found")

	// ErrNotFound is returned when a Document cannot be found within a Shelf.
	ErrNotFound = errors.New("document not found")
)

Functions

func CreateShelf

func CreateShelf(id uuid.UUID, name string) command.Command

CreateShelf returns the command to create a shelf.

func HandleCommands

func HandleCommands(ctx context.Context, bus command.Bus, shelfs Repository, storage media.Storage) <-chan error

HandleCommand handles commands until ctx is canceled.

func MakeNonUnique

func MakeNonUnique(shelfID, documentID uuid.UUID) command.Command

MakeNonUnique returns the command to remove the uniqueness of a document within a shelf.

func MakeUnique

func MakeUnique(shelfID, documentID uuid.UUID, uniqueName string) command.Command

MakeUnique returns the command to make a document unique within a shelf.

func RegisterCommands

func RegisterCommands(r *codec.GobRegistry)

RegisterCommand registers document commands.

func RegisterEvents

func RegisterEvents(r *codec.GobRegistry)

RegisterEvents registers Shelf events into an event registry.

func Remove

func Remove(shelfID, documentID uuid.UUID) command.Command

Remove returns the command to remove a document from a shelf.

func Rename

func Rename(shelfID, documentID uuid.UUID, name string) command.Command

Rename returns the command to rename a document in a shelf.

func Tag

func Tag(shelfID, documentID uuid.UUID, tags []string) command.Command

Tag returns the command to add tags to a document of a shelf.

func Untag

func Untag(shelfID, documentID uuid.UUID, tags []string) command.Command

Untag returns the command to remove tags from a document of a shelf.

Types

type Document

type Document struct {
	media.Document

	ID uuid.UUID `json:"id"`

	// UniqueName is the unique name of the document. UniqueName may be
	// empty but if it is not, it should be unique.
	UniqueName string `json:"uniqueName"`
}

Document is a document in a Shelf.

type DocumentAddedData

type DocumentAddedData struct {
	Document Document
}

DocumentAddedData is the event data for the DocumentAdded event.

type DocumentMadeNonUniqueData

type DocumentMadeNonUniqueData struct {
	DocumentID uuid.UUID
	UniqueName string
}

DocumentMadeNonUniqueData is the event data for the DocumentMadeNonUnique event.

type DocumentMadeUniqueData

type DocumentMadeUniqueData struct {
	DocumentID uuid.UUID
	UniqueName string
}

DocumentMadeUniqueData is the event data for the DocumentMadeUnique event.

type DocumentRemovedData

type DocumentRemovedData struct {
	Document    Document
	DeleteError string
}

DocumentRemovedData is the event data for the DocumentRemoved event.

type DocumentRenamedData

type DocumentRenamedData struct {
	DocumentID uuid.UUID
	OldName    string
	Name       string
}

DocumentRenamedData is the event data for the DocumentRenamed event.

type DocumentReplacedData

type DocumentReplacedData struct {
	Document Document
}

DocumentReplacedData is the event data for the DocumentReplaced event.

type DocumentTaggedData

type DocumentTaggedData struct {
	DocumentID uuid.UUID
	Tags       []string
}

DocumentTaggedData is the event data for the DocumentTagged event.

type DocumentUntaggedData

type DocumentUntaggedData struct {
	DocumentID uuid.UUID
	Tags       []string
}

DocumentUntaggedData is the event data for the DocumentUntagged event.

type JSONShelf

type JSONShelf struct {
	ID        uuid.UUID  `json:"id"`
	Name      string     `json:"name"`
	Documents []Document `json:"documents"`
}

func (JSONShelf) Document

func (s JSONShelf) Document(id uuid.UUID) (Document, error)

Document returns the Document with the given UUID or ErrDocumentNotFound.

type Lookup

type Lookup struct {
	// contains filtered or unexported fields
}

Lookup provides lookup of Shelf UUIDs. It is thread-safe.

func NewLookup

func NewLookup() *Lookup

NewLookup returns a new Lookup.

func (*Lookup) ApplyEvent

func (l *Lookup) ApplyEvent(evt event.Event)

ApplyEvent applies aggregate events.

func (*Lookup) Project

func (l *Lookup) Project(ctx context.Context, bus event.Bus, store event.Store, opts ...schedule.ContinuousOption) (<-chan error, error)

Project projects the Lookup in a new goroutine and returns a channel of asynchronous errors.

func (*Lookup) ShelfName

func (l *Lookup) ShelfName(name string) (uuid.UUID, bool)

ShelfName returns the UUID of the Shelf with the given name, or false if the Lookup has no UUID for name.

func (*Lookup) UniqueName

func (l *Lookup) UniqueName(shelfID uuid.UUID, uniqueName string) (uuid.UUID, bool)

UniqueName returns the UUID of the Document with the given UniqueName in the Shelf with the given UUID, or false if Lookup has no UUID for uniqueName.

type Repository

type Repository interface {
	// Save stores a Shelf in the underlying store.
	Save(context.Context, *Shelf) error

	// Fetch returns the Shelf with the specified UUID or ErrShelfNotFound.
	Fetch(context.Context, uuid.UUID) (*Shelf, error)

	// Delete deletes the given Shelf from the Repository.
	Delete(context.Context, *Shelf) error

	// Use fetches the Shelf with the specified UUID, calls the provided
	// function with that Shelf and then saves the Shelf, but only if the
	// function returns nil.
	Use(context.Context, uuid.UUID, func(*Shelf) error) error
}

Repository stores and retrieves Documents.

func GoesRepository

func GoesRepository(repo aggregate.Repository) Repository

GoesRepository returns a Repository that uses an aggregate.Repository under the hood.

type SearchOption

type SearchOption func(*searchConfig)

A SearchOption is used to filter Documents in a search.

func ForName

func ForName(names ...string) SearchOption

ForName returns a SearchOption that filters Documents by their names. A Document is included in the result if it has one of the provided names.

func ForRegexp

func ForRegexp(expr *regexp.Regexp) SearchOption

ForRegexp returns a SearchOption that filters Documents by a regular expression. A Document is included in the result if expr matches on either the Name, UniqueName, Disk or Path of the Document.

func ForTag

func ForTag(tags ...string) SearchOption

ForTag returns a SearchOption that filters Documents by their tags. A Document is included in the result if it has at least one of the provided tags.

type Shelf

type Shelf struct {
	*aggregate.Base

	Name      string
	Documents []Document
}

Shelf is a named collection of Documents.

func NewShelf

func NewShelf(id uuid.UUID) *Shelf

NewShelf returns a new Shelf.

func (*Shelf) Add

func (s *Shelf) Add(ctx context.Context, storage media.Storage, r io.Reader, uniqueName, name, disk, path string) (Document, error)

Add uploads the file in r to storage, adds it as a Document to the Shelf and returns the Document. If the Shelf wasn't created yet, ErrShelfNotCreated is returned.

If uniqueName is a non-empty string, it must be unique across all existing Documents in the Shelf. Documents with a UniqueName can be accessed by their unique names. If uniqueName is already in use by another Document, ErrDuplicateUniqueName is returned.

func (*Shelf) ApplyEvent

func (s *Shelf) ApplyEvent(evt event.Event)

ApplyEvent applies aggregate events.

func (*Shelf) Create

func (s *Shelf) Create(name string) error

Create creates the Shelf by giving it a name. If name is empty, ErrEmptyName is returned. If the Shelf was already created, ErrShelfAlreadyCreated is returned.

func (*Shelf) Document

func (s *Shelf) Document(id uuid.UUID) (Document, error)

Document returns the Document with the given UUID or ErrDocumentNotFound.

func (*Shelf) Find

func (s *Shelf) Find(uniqueName string) (Document, error)

Find returns the Document with the provided UniqueName or ErrDocumentNotFound.

func (*Shelf) JSON

func (s *Shelf) JSON() JSONShelf

func (*Shelf) MakeNonUnique

func (s *Shelf) MakeNonUnique(id uuid.UUID) (Document, error)

MakeNonUnique removes the UniqueName of the Document with the given UUID. If the Document cannot be found in the Shelf, ErrDocumentNotFound is returned.

func (*Shelf) MakeUnique

func (s *Shelf) MakeUnique(id uuid.UUID, uniqueName string) (Document, error)

MakeUnique gives the Document with the given UUID the UniqueName uniqueName. If the Document cannot be found in the Shelf, ErrDocumentNotFound is returned. If uniqueName is an empty string, ErrEmptyName is returned. If uniqueName is already taken by another Document, ErrDuplicateUniqueName is returned.

func (*Shelf) MarshalSnapshot

func (s *Shelf) MarshalSnapshot() ([]byte, error)

MarshalSnapshot implements snapshot.Marshaler.

func (*Shelf) Remove

func (s *Shelf) Remove(ctx context.Context, storage media.Storage, id uuid.UUID) error

Remove deletes the Document with the given UUID from storage and removes it from the Shelf. If the Shelf wasn't created yet, ErrShelfNotCreated is returned.

No error is returned if the Storage fails to delete the file. Instead, the new `DocumentRemoved` aggregate event of the Shelf will contain the deletion error.

func (*Shelf) RenameDocument

func (s *Shelf) RenameDocument(id uuid.UUID, name string) (Document, error)

RenameDocument renames the Document with the given UUID. It does not rename the UniqueName of a Document; use s.MakeUnique to do that. If the Document cannot be found in the Shelf, ErrDocumentNotFound is returned.

func (*Shelf) Replace

func (s *Shelf) Replace(ctx context.Context, storage media.Storage, r io.Reader, id uuid.UUID) (Document, error)

Replace replaces the document with the given UUID with the document in r.

func (*Shelf) Search

func (s *Shelf) Search(opts ...SearchOption) []Document

Search returns the Documents in s that are allowed by the provided SearchOptions.

func (*Shelf) Tag

func (s *Shelf) Tag(id uuid.UUID, tags ...string) (Document, error)

Tag tags the Document with the given UUID with tags. If the Document cannot be found in the Shelf, ErrDocumentNotFound is returned.

func (*Shelf) UnmarshalSnapshot

func (s *Shelf) UnmarshalSnapshot(b []byte) error

UnmarshalSnapshot implements snapshot.Unmarshaler.

func (*Shelf) Untag

func (s *Shelf) Untag(id uuid.UUID, tags ...string) (Document, error)

Untag removes tags from the Document with the given UUID. If the Document cannot be found in the Shelf, ErrDocumentNotFound is returned.

type ShelfCreatedData

type ShelfCreatedData struct {
	Name string
}

ShelfCreatedData is the event data for the ShelfCreated event.

Directories

Path Synopsis
Package mock_document is a generated GoMock package.
Package mock_document is a generated GoMock package.

Jump to

Keyboard shortcuts

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