Documentation ¶
Index ¶
- Constants
- Variables
- func CreateShelf(id uuid.UUID, name string) command.Command
- func HandleCommands(ctx context.Context, bus command.Bus, shelfs Repository, storage media.Storage) <-chan error
- func MakeNonUnique(shelfID, documentID uuid.UUID) command.Command
- func MakeUnique(shelfID, documentID uuid.UUID, uniqueName string) command.Command
- func RegisterCommands(r command.Registry)
- func RegisterEvents(r event.Registry)
- func Remove(shelfID, documentID uuid.UUID) command.Command
- func Rename(shelfID, documentID uuid.UUID, name string) command.Command
- func Tag(shelfID, documentID uuid.UUID, tags []string) command.Command
- func Untag(shelfID, documentID uuid.UUID, tags []string) command.Command
- type Document
- type DocumentAddedData
- type DocumentMadeNonUniqueData
- type DocumentMadeUniqueData
- type DocumentRemovedData
- type DocumentRenamedData
- type DocumentReplacedData
- type DocumentTaggedData
- type DocumentUntaggedData
- type JSONShelf
- type Lookup
- type Repository
- type SearchOption
- type Shelf
- func (s *Shelf) Add(ctx context.Context, storage media.Storage, r io.Reader, ...) (Document, error)
- func (s *Shelf) ApplyEvent(evt event.Event)
- func (s *Shelf) Create(name string) error
- func (s *Shelf) Document(id uuid.UUID) (Document, error)
- func (s *Shelf) Find(uniqueName string) (Document, error)
- func (s *Shelf) JSON() JSONShelf
- func (s *Shelf) MakeNonUnique(id uuid.UUID) (Document, error)
- func (s *Shelf) MakeUnique(id uuid.UUID, uniqueName string) (Document, error)
- func (s *Shelf) MarshalSnapshot() ([]byte, error)
- func (s *Shelf) Remove(ctx context.Context, storage media.Storage, id uuid.UUID) error
- func (s *Shelf) RenameDocument(id uuid.UUID, name string) (Document, error)
- func (s *Shelf) Replace(ctx context.Context, storage media.Storage, r io.Reader, id uuid.UUID) (Document, error)
- func (s *Shelf) Search(opts ...SearchOption) []Document
- func (s *Shelf) Tag(id uuid.UUID, tags ...string) (Document, error)
- func (s *Shelf) UnmarshalSnapshot(b []byte) error
- func (s *Shelf) Untag(id uuid.UUID, tags ...string) (Document, error)
- type ShelfCreatedData
Constants ¶
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.document_made_unique" MakeNonUniqueCommand = "cms.media.document.shelf.document_made_non_unique" TagCommand = "cms.media.document.shelf.document_tagged" UntagCommand = "cms.media.document.shelf.document_untagged" )
Shelf commands.
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
const Aggregate = "cms.media.document.shelf"
Aggregate is the name of the Document aggregate.
Variables ¶
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 ¶
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 ¶
MakeNonUnique returns the command to remove the uniqueness of a document within a shelf.
func MakeUnique ¶
MakeUnique returns the command to make a document unique within a shelf.
func RegisterCommands ¶
RegisterCommand registers document commands.
func RegisterEvents ¶
RegisterEvents registers Shelf events into an event registry.
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 ¶
DocumentMadeNonUniqueData is the event data for the DocumentMadeNonUnique event.
type DocumentMadeUniqueData ¶
DocumentMadeUniqueData is the event data for the DocumentMadeUnique event.
type DocumentRemovedData ¶
DocumentRemovedData is the event data for the DocumentRemoved event.
type DocumentRenamedData ¶
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 ¶
DocumentTaggedData is the event data for the DocumentTagged event.
type DocumentUntaggedData ¶
DocumentUntaggedData is the event data for the DocumentUntagged event.
type JSONShelf ¶
type Lookup ¶
type Lookup struct {
// contains filtered or unexported fields
}
Lookup provides lookup of Shelf UUIDs. It is thread-safe.
func (*Lookup) ApplyEvent ¶
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.
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 ¶
Shelf is a named collection of Documents.
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 ¶
ApplyEvent applies aggregate events.
func (*Shelf) Create ¶
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) MakeNonUnique ¶
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 ¶
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 ¶
MarshalSnapshot implements snapshot.Marshaler.
func (*Shelf) Remove ¶
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 ¶
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 ¶
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 ¶
UnmarshalSnapshot implements snapshot.Unmarshaler.
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. |