Documentation
¶
Overview ¶
Package state provides tools to maintain an index of all medias that have been backed up.
Index ¶
- Variables
- func Init(repositoryAdapter RepositoryAdapter)
- type Album
- type AlbumAutoCreateLookupStrategy
- type AlbumCreated
- type AlbumCreatedAsTimelineMutation
- type AlbumCreatedObserver
- type AlbumCreatedObserverFunc
- type AlbumDatesAmended
- type AlbumDatesAmendedAsTimelineMutation
- type AlbumDatesAmendedObserver
- type AlbumDatesAmendedObserverFunc
- type AlbumDatesUpdated
- type AlbumDeleted
- type AlbumDeletedAsTimelineMutation
- type AlbumDeletedObserver
- type AlbumDeletedObserverFunc
- type AlbumId
- type AlbumLookupStrategy
- type AlbumNameUpdated
- type AlbumQueries
- func (a *AlbumQueries) CountMedia(ctx context.Context, album ...AlbumId) (map[AlbumId]int, error)
- func (a *AlbumQueries) FindAlbum(ctx context.Context, albumId AlbumId) (*Album, error)
- func (a *AlbumQueries) FindAlbumsById(ctx context.Context, ids []AlbumId) ([]*Album, error)
- func (a *AlbumQueries) FindAlbumsByOwner(ctx context.Context, owner ownermodel.Owner) ([]*Album, error)
- type AlbumReference
- type AlbumRenamed
- type AlbumRenamedAsTimelineMutation
- type AlbumRenamedObserver
- type AlbumRenamedObserverFunc
- type AmendAlbumDates
- type BulkCreateAlbum
- type CountMediasBySelectorsFunc
- type CountMediasBySelectorsPort
- type CreateAlbum
- type CreateAlbumRequest
- type CreateMediaRequest
- type DatesUpdate
- type DeleteAlbum
- type DryRunLookupStrategy
- type FindExistingSignaturePort
- type FindMediaRequest
- type FolderName
- type InMemoryMedia
- type InsertMedias
- type InsertMediasObserver
- type InsertMediasRepositoryPort
- type MediaDetails
- type MediaFutureReference
- type MediaId
- type MediaMeta
- type MediaOrientation
- type MediaPage
- type MediaQueries
- type MediaQueriesInMemory
- type MediaReadRepository
- type MediaSelector
- type MediaSignature
- type MediaTransferRecords
- type MediaType
- type MediasInsertSimulator
- type PageRequest
- type PrioritySegment
- type RenameAlbum
- type RenameAlbumRequest
- type RepositoryAdapter
- type StatefulAlbumReferencer
- type ThreadSafeAlbumReferencer
- type TimeRange
- type Timeline
- func (t *Timeline) AppendAlbum(album *Album) (*Timeline, error)
- func (t *Timeline) Debug() string
- func (t *Timeline) FindAllAt(date time.Time) []*Album
- func (t *Timeline) FindAt(date time.Time) (*Album, bool)
- func (t *Timeline) FindForAlbum(albumId AlbumId) (segments []PrioritySegment)
- func (t *Timeline) FindSegmentsBetween(start, end time.Time) (segments []PrioritySegment)
- func (t *Timeline) FindSegmentsBetweenAndFilter(start, end time.Time, albumId AlbumId) (segments []PrioritySegment)
- type TimelineAggregate
- func (t *TimelineAggregate) AmendDates(albumId AlbumId, start, end time.Time) (*AlbumDatesUpdated, error)
- func (t *TimelineAggregate) CreateNewAlbum(request CreateAlbumRequest) (Album, MediaTransferRecords, error)
- func (t *TimelineAggregate) FindAt(date time.Time) (*Album, bool)
- func (t *TimelineAggregate) RemoveAlbum(deletedAlbumId AlbumId) (MediaTransferRecords, []MediaSelector, error)
- func (t *TimelineAggregate) RenameAlbum(request RenameAlbumRequest) (*AlbumNameUpdated, error)
- type TimelineLookupStrategy
- type TimelineMutationObserver
- type TimelineMutationObserverFunc
- type TimelinePersistencePort
- type TimelineRepository
- type TimelineRepositoryAdapter
- type TransferMediasFromRepository
- type TransferMediasFunc
- type TransferMediasRepositoryPort
- type TransferMediasService
- type TransferredMedias
Constants ¶
This section is empty.
Variables ¶
var ( AlbumNameMandatoryErr = errors.New("Album name is mandatory") AlbumStartAndEndDateMandatoryErr = errors.New("Start and End times are mandatory") AlbumEndDateMustBeAfterStartErr = errors.New("Album end must be strictly after its start") AlbumFolderNameAlreadyTakenErr = errors.New("Album folder name is already taken") )
var ( AlbumNotFoundErr = errors.New("album hasn't been found") EmptyFolderNameError = errors.New("folderName is mandatory and must be not empty") )
var (
DuplicatedAlbumError = errors.New("Timeline cannot contains duplicated albums")
)
var (
MediaNotFoundError = fmt.Errorf("media not found")
)
var (
NoAlbumLookedUpError = errors.New("no album matching")
)
var (
OrphanedMediasErr = errors.New("albums cannot be deleted or amended if it orphans medias.")
)
Functions ¶
func Init ¶
func Init(repositoryAdapter RepositoryAdapter)
Init must be called before using this package.
Types ¶
type Album ¶
type Album struct {
AlbumId
Name string // Name for displaying purpose, not unique
Start time.Time // Start is datetime inclusive
End time.Time // End is the datetime exclusive
}
Album is a logical grouping of medias ; also used to physically store media next to each others.
type AlbumAutoCreateLookupStrategy ¶ added in v1.5.58
type AlbumAutoCreateLookupStrategy struct {
BulkCreateAlbum *BulkCreateAlbum
}
AlbumAutoCreateLookupStrategy delegates to the BulkCreateAlbum use case to create a quarterly album covering mediaTime, reusing the timeline held by StatefulAlbumReferencer so subsequent lookups see the newly created album without a second load from the repository.
func (*AlbumAutoCreateLookupStrategy) LookupAlbum ¶ added in v1.5.58
func (a *AlbumAutoCreateLookupStrategy) LookupAlbum(ctx context.Context, owner ownermodel.Owner, timeline *TimelineAggregate, mediaTime time.Time) (AlbumReference, error)
type AlbumCreated ¶ added in v1.9.52
type AlbumCreated struct {
CreatedAlbum Album
TransferredMedias TransferredMedias
}
AlbumCreated is fired after a new album has been persisted and its overlapping medias have been transferred: it carries the newly created album and the medias that were actually moved into it (if any).
type AlbumCreatedAsTimelineMutation ¶ added in v1.9.52
type AlbumCreatedAsTimelineMutation struct {
TimelineMutationObserver TimelineMutationObserver
}
func (*AlbumCreatedAsTimelineMutation) OnAlbumCreated ¶ added in v1.9.52
func (a *AlbumCreatedAsTimelineMutation) OnAlbumCreated(ctx context.Context, event AlbumCreated) error
type AlbumCreatedObserver ¶ added in v1.9.52
type AlbumCreatedObserver interface {
OnAlbumCreated(ctx context.Context, event AlbumCreated) error
}
type AlbumCreatedObserverFunc ¶ added in v1.9.52
type AlbumCreatedObserverFunc func(ctx context.Context, event AlbumCreated) error
func (AlbumCreatedObserverFunc) OnAlbumCreated ¶ added in v1.9.52
func (f AlbumCreatedObserverFunc) OnAlbumCreated(ctx context.Context, event AlbumCreated) error
type AlbumDatesAmended ¶ added in v1.9.52
type AlbumDatesAmended struct {
DatesUpdate DatesUpdate
TransferredMedias TransferredMedias
}
AlbumDatesAmended is fired after an album's dates have been persisted and the medias affected by the change have been transferred to their new albums.
type AlbumDatesAmendedAsTimelineMutation ¶ added in v1.9.52
type AlbumDatesAmendedAsTimelineMutation struct {
TimelineMutationObserver TimelineMutationObserver
}
AlbumDatesAmendedAsTimelineMutation adapts an AlbumDatesAmendedObserver notification into a TimelineMutationObserver call, forwarding only the TransferredMedias carried by the event. This bridges the AlbumDatesAmended event to the observers that still listen on the legacy TimelineMutationObserver interface (archive relocator, view counters, ...).
func (*AlbumDatesAmendedAsTimelineMutation) OnAlbumDatesAmended ¶ added in v1.9.52
func (a *AlbumDatesAmendedAsTimelineMutation) OnAlbumDatesAmended(ctx context.Context, event AlbumDatesAmended) error
type AlbumDatesAmendedObserver ¶ added in v1.5.58
type AlbumDatesAmendedObserver interface {
OnAlbumDatesAmended(ctx context.Context, event AlbumDatesAmended) error
}
type AlbumDatesAmendedObserverFunc ¶ added in v1.5.58
type AlbumDatesAmendedObserverFunc func(ctx context.Context, event AlbumDatesAmended) error
func (AlbumDatesAmendedObserverFunc) OnAlbumDatesAmended ¶ added in v1.5.58
func (f AlbumDatesAmendedObserverFunc) OnAlbumDatesAmended(ctx context.Context, event AlbumDatesAmended) error
type AlbumDatesUpdated ¶ added in v1.9.52
type AlbumDatesUpdated struct {
DatesUpdate DatesUpdate
MediaTransfer MediaTransferRecords
Orphaned []MediaSelector
}
AlbumDatesUpdated carries the outcome of an album date amendment as computed by the TimelineAggregate: the DatesUpdate (with the previous start/end preserved so the caller can detect a no-op via DatesUpdate.DatesNotChanged()), the media transfer records needed to reallocate medias to their new album, and any selectors that would be left orphan.
type AlbumDeleted ¶ added in v1.9.52
type AlbumDeleted struct {
DeletedAlbumId AlbumId
TransferredMedias TransferredMedias
}
AlbumDeleted is fired after an album has been deleted and its medias transferred to the surrounding albums: it carries the id of the album that has been removed and the medias that were actually moved to another album.
type AlbumDeletedAsTimelineMutation ¶ added in v1.9.52
type AlbumDeletedAsTimelineMutation struct {
TimelineMutationObserver TimelineMutationObserver
}
AlbumDeletedAsTimelineMutation adapts an AlbumDeletedObserver notification into a TimelineMutationObserver call, forwarding only the TransferredMedias carried by the event. This bridges the AlbumDeleted event to the observers that still listen on the legacy TimelineMutationObserver interface (archive relocator, view counters, ...).
func (*AlbumDeletedAsTimelineMutation) OnAlbumDeleted ¶ added in v1.9.52
func (a *AlbumDeletedAsTimelineMutation) OnAlbumDeleted(ctx context.Context, event AlbumDeleted) error
type AlbumDeletedObserver ¶ added in v1.9.52
type AlbumDeletedObserver interface {
OnAlbumDeleted(ctx context.Context, event AlbumDeleted) error
}
type AlbumDeletedObserverFunc ¶ added in v1.9.52
type AlbumDeletedObserverFunc func(ctx context.Context, event AlbumDeleted) error
func (AlbumDeletedObserverFunc) OnAlbumDeleted ¶ added in v1.9.52
func (f AlbumDeletedObserverFunc) OnAlbumDeleted(ctx context.Context, event AlbumDeleted) error
type AlbumId ¶
type AlbumId struct {
Owner ownermodel.Owner
FolderName FolderName
}
func NewAlbumIdFromStrings ¶ added in v1.5.33
NewAlbumIdFromStrings creates an AlbumId from 2 strings ; it doesn't guaranty its validity, use AlbumId.IsValid to check if any error.
type AlbumLookupStrategy ¶ added in v1.5.58
type AlbumLookupStrategy interface {
// LookupAlbum returns the AlbumReference for the given mediaTime, or NoAlbumLookedUpError if it can't find any (or a technical error)
LookupAlbum(ctx context.Context, owner ownermodel.Owner, timeline *TimelineAggregate, mediaTime time.Time) (AlbumReference, error)
}
type AlbumNameUpdated ¶ added in v1.9.52
type AlbumNameUpdated struct {
ExistingAlbum Album
RenamedAlbum Album
MediaTransfer MediaTransferRecords
}
AlbumNameUpdated carries the outcome of a folder-name-changing rename as computed by the TimelineAggregate: the existing album to remove, the new album to insert, and the media transfer that moves the existing album's medias into the new one.
type AlbumQueries ¶ added in v1.5.49
type AlbumQueries struct {
Repository RepositoryAdapter
}
func (*AlbumQueries) CountMedia ¶ added in v1.5.50
func (*AlbumQueries) FindAlbumsById ¶ added in v1.5.49
func (*AlbumQueries) FindAlbumsByOwner ¶ added in v1.5.49
func (a *AlbumQueries) FindAlbumsByOwner(ctx context.Context, owner ownermodel.Owner) ([]*Album, error)
type AlbumReference ¶ added in v1.5.54
type AlbumRenamed ¶ added in v1.9.52
type AlbumRenamed struct {
ExistingAlbum Album
RenamedAlbum Album
TransferredMedias TransferredMedias
}
type AlbumRenamedAsTimelineMutation ¶ added in v1.9.52
type AlbumRenamedAsTimelineMutation struct {
TimelineMutationObserver TimelineMutationObserver
}
AlbumRenamedAsTimelineMutation adapts an AlbumRenamedObserver notification into a TimelineMutationObserver call, forwarding only the TransferredMedias carried by the event. This bridges the AlbumRenamed event to the observers that still listen on the legacy TimelineMutationObserver interface (archive relocator, view counters, ...).
func (*AlbumRenamedAsTimelineMutation) OnAlbumRenamed ¶ added in v1.9.52
func (a *AlbumRenamedAsTimelineMutation) OnAlbumRenamed(ctx context.Context, event AlbumRenamed) error
type AlbumRenamedObserver ¶ added in v1.9.52
type AlbumRenamedObserver interface {
OnAlbumRenamed(ctx context.Context, event AlbumRenamed) error
}
type AlbumRenamedObserverFunc ¶ added in v1.9.52
type AlbumRenamedObserverFunc func(ctx context.Context, event AlbumRenamed) error
func (AlbumRenamedObserverFunc) OnAlbumRenamed ¶ added in v1.9.52
func (f AlbumRenamedObserverFunc) OnAlbumRenamed(ctx context.Context, event AlbumRenamed) error
type AmendAlbumDates ¶ added in v1.5.45
type AmendAlbumDates struct {
TimelineRepository TimelineRepository
CountMediasBySelectorsPort CountMediasBySelectorsPort
TransferMediasService TransferMediasService
AlbumDatesAmendedObservers []AlbumDatesAmendedObserver
}
AmendAlbumDates changes the start/end dates of an album, transfers medias affected by the date change to their new album, then fires an AlbumDatesAmended event. When some medias would be left orphan (no album covers them anymore) the operation is aborted and OrphanedMediasErr is returned before any change is persisted.
func NewAmendAlbumDates ¶ added in v1.5.45
func NewAmendAlbumDates( timelineRepository TimelineRepository, countMediasBySelectors CountMediasBySelectorsPort, transferMedias TransferMediasService, observers ...AlbumDatesAmendedObserver, ) *AmendAlbumDates
NewAmendAlbumDates creates the service to amend the dates of an album.
func (*AmendAlbumDates) AmendAlbumDates ¶ added in v1.5.45
type BulkCreateAlbum ¶ added in v1.9.52
type BulkCreateAlbum struct {
TimelineRepository TimelineRepository
TransferMediasService TransferMediasService
AlbumCreatedObservers []AlbumCreatedObserver
}
func (*BulkCreateAlbum) Create ¶ added in v1.9.52
func (c *BulkCreateAlbum) Create(ctx context.Context, timeline *TimelineAggregate, request CreateAlbumRequest) (*AlbumId, error)
type CountMediasBySelectorsFunc ¶ added in v1.5.41
type CountMediasBySelectorsFunc func(ctx context.Context, owner ownermodel.Owner, selectors []MediaSelector) (int, error)
func (CountMediasBySelectorsFunc) CountMediasBySelectors ¶ added in v1.5.41
func (f CountMediasBySelectorsFunc) CountMediasBySelectors(ctx context.Context, owner ownermodel.Owner, selectors []MediaSelector) (int, error)
type CountMediasBySelectorsPort ¶ added in v1.5.41
type CountMediasBySelectorsPort interface {
CountMediasBySelectors(ctx context.Context, owner ownermodel.Owner, selectors []MediaSelector) (int, error)
}
type CreateAlbum ¶
type CreateAlbum struct {
TimelineRepository TimelineRepository
BulkCreateAlbum *BulkCreateAlbum
}
CreateAlbum inserts a new album and, if it overlaps with existing albums, transfers the overlapping medias into it. On success, an AlbumCreated event is fired to every observer.
func NewAlbumCreate ¶ added in v1.5.42
func NewAlbumCreate( TimelineRepository TimelineRepository, TransferMedias TransferMediasService, AlbumCreatedObservers ...AlbumCreatedObserver, ) *CreateAlbum
NewAlbumCreate creates the service to create a new album, including the transfer of medias.
func (*CreateAlbum) Create ¶ added in v1.5.33
func (c *CreateAlbum) Create(ctx context.Context, request CreateAlbumRequest) (*AlbumId, error)
type CreateAlbumRequest ¶ added in v1.5.33
type CreateAlbumRequest struct {
Owner ownermodel.Owner
Name string
Start time.Time
End time.Time
ForcedFolderName string
}
CreateAlbumRequest is a request to create a new album
func (*CreateAlbumRequest) IsValid ¶ added in v1.5.33
func (c *CreateAlbumRequest) IsValid() error
func (*CreateAlbumRequest) String ¶ added in v1.5.33
func (c *CreateAlbumRequest) String() string
type CreateMediaRequest ¶
type CreateMediaRequest struct {
Id MediaId // Id is generated from its signature with GenerateMediaId(MediaSignature)
Signature MediaSignature // Signature is the business key of a media
FolderName FolderName // FolderName is the name of the album the media is in
Filename string // Filename is a user-friendly name that have the right extension.
Type MediaType
Details MediaDetails
}
CreateMediaRequest is the request to add a new media to an album belonging to the same Owner
type DatesUpdate ¶ added in v1.5.58
func (*DatesUpdate) DatesNotChanged ¶ added in v1.5.58
func (a *DatesUpdate) DatesNotChanged() bool
type DeleteAlbum ¶
type DeleteAlbum struct {
TimelineRepository TimelineRepository
CountMediasBySelectors CountMediasBySelectorsPort
TransferMediasService TransferMediasService
AlbumDeletedObservers []AlbumDeletedObserver
}
DeleteAlbum removes an album from the catalog: any media it currently holds is moved to the surrounding albums (as computed by the TimelineAggregate), and an AlbumDeleted event is fired once the row has been removed.
func NewDeleteAlbum ¶ added in v1.5.41
func NewDeleteAlbum( TimelineRepository TimelineRepository, CountMediasBySelectors CountMediasBySelectorsPort, TransferMedias TransferMediasService, AlbumDeletedObservers ...AlbumDeletedObserver, ) *DeleteAlbum
NewDeleteAlbum creates the service to delete an album, transferring its medias to the surrounding albums when possible.
func (*DeleteAlbum) DeleteAlbum ¶ added in v1.5.41
func (d *DeleteAlbum) DeleteAlbum(ctx context.Context, albumId AlbumId) error
type DryRunLookupStrategy ¶ added in v1.5.58
type DryRunLookupStrategy struct{}
func (*DryRunLookupStrategy) LookupAlbum ¶ added in v1.5.58
func (d *DryRunLookupStrategy) LookupAlbum(ctx context.Context, owner ownermodel.Owner, timeline *TimelineAggregate, mediaTime time.Time) (AlbumReference, error)
type FindExistingSignaturePort ¶ added in v1.5.54
type FindExistingSignaturePort interface {
FindSignatures(ctx context.Context, owner ownermodel.Owner, signatures []MediaSignature) (map[MediaSignature]MediaId, error)
}
type FindMediaRequest ¶
type FindMediaRequest struct {
Owner ownermodel.Owner
AlbumFolderNames map[FolderName]interface{} // AlbumFolderNames is a set of folder names (map value is nil)
Ranges []TimeRange // Ranges is optional, if empty no restriction will be applied
}
FindMediaRequest is a filter that is applied to find medias within a time range.
func NewFindMediaRequest ¶
func NewFindMediaRequest(owner ownermodel.Owner) *FindMediaRequest
func (*FindMediaRequest) String ¶
func (m *FindMediaRequest) String() string
func (*FindMediaRequest) WithAlbum ¶
func (m *FindMediaRequest) WithAlbum(folderNames ...FolderName) *FindMediaRequest
func (*FindMediaRequest) WithinRange ¶
func (m *FindMediaRequest) WithinRange(start, end time.Time) *FindMediaRequest
type FolderName ¶ added in v1.5.33
type FolderName string
FolderName is a normalised ID unique per Owner
func NewFolderName ¶ added in v1.5.33
func NewFolderName(name string) FolderName
NewFolderName creates a FolderName with a normalised value ; it can still be invalid (empty)
func (FolderName) IsValid ¶ added in v1.5.33
func (n FolderName) IsValid() error
func (FolderName) String ¶ added in v1.5.33
func (n FolderName) String() string
type InMemoryMedia ¶ added in v1.6.4
func NewInMemoryMedia ¶ added in v1.6.4
func NewInMemoryMedia(id MediaId, albumId AlbumId) InMemoryMedia
type InsertMedias ¶
type InsertMedias struct {
InsertMediasRepository InsertMediasRepositoryPort
InsertMediasObservers []InsertMediasObserver
}
InsertMedias is a use case to pre-generate ids and store media metadata
func NewInsertMedias ¶ added in v1.5.47
func NewInsertMedias( InsertMediasRepository InsertMediasRepositoryPort, InsertMediasObservers ...InsertMediasObserver, ) *InsertMedias
func (*InsertMedias) Insert ¶ added in v1.5.47
func (i *InsertMedias) Insert(ctx context.Context, owner ownermodel.Owner, medias []CreateMediaRequest) error
type InsertMediasObserver ¶ added in v1.5.47
type InsertMediasRepositoryPort ¶ added in v1.5.47
type InsertMediasRepositoryPort interface {
// InsertMedias bulks insert medias
InsertMedias(ctx context.Context, owner ownermodel.Owner, media []CreateMediaRequest) error
}
type MediaDetails ¶
type MediaDetails struct {
Width, Height int
DateTime time.Time
Orientation MediaOrientation
Make string
Model string
GPSLatitude, GPSLongitude float64
Duration int64 // Duration is the length, in milliseconds, of a video
VideoEncoding string // VideoEncoding is the codec used to encode the video (ex: 'H264')
}
MediaDetails are extracted from the metadata within photos and videos and stored as it.
type MediaFutureReference ¶ added in v1.5.54
type MediaFutureReference struct {
Signature MediaSignature
ProvisionalMediaId MediaId
AlreadyExists bool
}
MediaFutureReference is the response of a simulation of inserting the media: the unique ID (if the media already exists) or a unique ID the media can use.
type MediaId ¶ added in v1.5.33
type MediaId string
func GenerateMediaId ¶
func GenerateMediaId(signature MediaSignature) (MediaId, error)
GenerateMediaId generate a unique ID for a media.
type MediaMeta ¶
type MediaMeta struct {
Id MediaId // Id is the unique identifier to use across all domains
Signature MediaSignature // Signature is the key used to get the image (or its location)
Filename string // Filename original filename when image was uploaded
Type MediaType
Details MediaDetails
}
MediaMeta is an entry (read) of a media in the state
type MediaOrientation ¶
type MediaOrientation string
type MediaPage ¶
type MediaPage struct {
NextPage string // NextPage is empty if no other pages
Content []*MediaMeta
}
MediaPage is the current page MediaMeta, and the token of the next page
type MediaQueries ¶ added in v1.6.4
type MediaQueries struct {
MediaReadRepository MediaReadRepository
}
func (*MediaQueries) FindMediaOwnership ¶ added in v1.6.4
func (q *MediaQueries) FindMediaOwnership(ctx context.Context, owner ownermodel.Owner, mediaId MediaId) (*AlbumId, error)
FindMediaOwnership returns the folderName containing the media, or AlbumNotFoundErr.
func (*MediaQueries) ListMedias ¶ added in v1.6.4
type MediaQueriesInMemory ¶ added in v1.6.4
type MediaQueriesInMemory struct {
Medias []InMemoryMedia
}
MediaQueriesInMemory is a copy of MediaQueries with an in-memory implementation
func (*MediaQueriesInMemory) FindMediaOwnership ¶ added in v1.6.4
func (q *MediaQueriesInMemory) FindMediaOwnership(ctx context.Context, owner ownermodel.Owner, mediaId MediaId) (*AlbumId, error)
FindMediaOwnership returns the folderName containing the media, or AlbumNotFoundErr.
func (*MediaQueriesInMemory) ListMedias ¶ added in v1.6.4
type MediaReadRepository ¶ added in v1.6.4
type MediaSelector ¶ added in v1.5.33
type MediaSelector struct {
//ExclusiveAlbum *AlbumId // ExclusiveAlbum is the Album in which medias are NOT (optional)
FromAlbums []AlbumId // FromAlbums is a list of potential origins of medias ; is mandatory on CreateAlbum case because media are not indexed by date, only per album.
Start time.Time // Start is the first date of matching medias, included
End time.Time // End is the last date of matching media, excluded at the second
}
func (MediaSelector) String ¶ added in v1.5.33
func (m MediaSelector) String() string
type MediaSignature ¶
func DecodeMediaId ¶
func DecodeMediaId(encodedId MediaId) (*MediaSignature, error)
DecodeMediaId reverse what the GenerateMediaId has done to find original signature.
func (MediaSignature) String ¶
func (s MediaSignature) String() string
func (MediaSignature) Value ¶ added in v1.5.57
func (s MediaSignature) Value() string
type MediaTransferRecords ¶ added in v1.5.33
type MediaTransferRecords map[AlbumId][]MediaSelector
MediaTransferRecords is a description of all medias that needs to be moved accordingly to the Timeline change
func (MediaTransferRecords) String ¶ added in v1.5.33
func (r MediaTransferRecords) String() string
type MediasInsertSimulator ¶ added in v1.5.54
type MediasInsertSimulator struct {
FindExistingSignaturePort FindExistingSignaturePort
}
func (*MediasInsertSimulator) SimulateInsertingMedia ¶ added in v1.5.54
func (m *MediasInsertSimulator) SimulateInsertingMedia(ctx context.Context, owner ownermodel.Owner, signatures []MediaSignature) ([]MediaFutureReference, error)
type PageRequest ¶
type PrioritySegment ¶
type RenameAlbum ¶
type RenameAlbum struct {
TimelineRepository TimelineRepository
TransferMediasService TransferMediasService
AlbumRenamedObservers []AlbumRenamedObserver
}
func NewRenameAlbum ¶ added in v1.5.43
func NewRenameAlbum( TimelineRepository TimelineRepository, TransferMedias TransferMediasService, AlbumRenamedObservers ...AlbumRenamedObserver, ) *RenameAlbum
NewRenameAlbum creates the service to rename an album.
func (*RenameAlbum) RenameAlbum ¶ added in v1.5.43
func (r *RenameAlbum) RenameAlbum(ctx context.Context, request RenameAlbumRequest) error
type RenameAlbumRequest ¶ added in v1.5.43
type RenameAlbumRequest struct {
CurrentId AlbumId
NewName string
RenameFolder bool // RenameFolder set to TRUE will create a new album with a FolderName generated from the NewName
ForcedFolderName string // ForcedFolderName set to non-empty will create a new album with the requested FolderName (RenameFolder is ignored)
}
func (RenameAlbumRequest) String ¶ added in v1.5.43
func (r RenameAlbumRequest) String() string
type RepositoryAdapter ¶
type RepositoryAdapter interface {
FindAlbumsByOwner(ctx context.Context, owner ownermodel.Owner) ([]*Album, error)
// FindAlbumByIds only returns found albums
FindAlbumByIds(ctx context.Context, ids ...AlbumId) ([]*Album, error)
CountMedia(ctx context.Context, album ...AlbumId) (map[AlbumId]int, error)
}
RepositoryAdapter brings persistence layer to catalog package
type StatefulAlbumReferencer ¶ added in v1.5.58
type StatefulAlbumReferencer struct {
Owner ownermodel.Owner
TimelineAggregate *TimelineAggregate
LookupStrategies []AlbumLookupStrategy // LookupStrategies will return the first matching album reference (not returning NoAlbumLookedUpError)
}
func (*StatefulAlbumReferencer) FindReference ¶ added in v1.5.58
func (a *StatefulAlbumReferencer) FindReference(ctx context.Context, mediaTime time.Time) (AlbumReference, error)
type ThreadSafeAlbumReferencer ¶ added in v1.6.13
type ThreadSafeAlbumReferencer struct {
Delegate *StatefulAlbumReferencer
// contains filtered or unexported fields
}
func NewAlbumAutoPopulateReferencer ¶ added in v1.5.54
func NewAlbumAutoPopulateReferencer( owner ownermodel.Owner, timelineRepository TimelineRepository, TransferMediasService TransferMediasService, AlbumCreatedObservers ...AlbumCreatedObserver, ) (*ThreadSafeAlbumReferencer, error)
NewAlbumAutoPopulateReferencer find reference of the albums that will receive the new medias, or creates a new one.
func NewAlbumDryRunReferencer ¶ added in v1.5.57
func NewAlbumDryRunReferencer( owner ownermodel.Owner, timelineRepository TimelineRepository, ) (*ThreadSafeAlbumReferencer, error)
NewAlbumDryRunReferencer find a reference of the album that wil receive the new media, or informs that a new album will be created (dry run).
func (*ThreadSafeAlbumReferencer) FindReference ¶ added in v1.6.13
func (t *ThreadSafeAlbumReferencer) FindReference(ctx context.Context, mediaTime time.Time) (AlbumReference, error)
type TimeRange ¶
TimeRange is of days, start is inclusive (at the second), end is exclusive (at the second)
type Timeline ¶
type Timeline struct {
// contains filtered or unexported fields
}
Timeline can be used to find to which album a media will belongs.
func NewTimeline ¶
NewTimeline creates a Timeline object used to compute overlaps between Album. List of albums must be sorted by Start date ASC (End sorting does not matter).
func (*Timeline) AppendAlbum ¶
AppendAlbum generates a new timeline from memory
func (*Timeline) FindForAlbum ¶
func (t *Timeline) FindForAlbum(albumId AlbumId) (segments []PrioritySegment)
func (*Timeline) FindSegmentsBetween ¶ added in v1.5.41
func (t *Timeline) FindSegmentsBetween(start, end time.Time) (segments []PrioritySegment)
FindSegmentsBetween returns a list of segments between start and end date. Segments will cover the whole period, but might not have any album.
func (*Timeline) FindSegmentsBetweenAndFilter ¶ added in v1.5.45
func (t *Timeline) FindSegmentsBetweenAndFilter(start, end time.Time, albumId AlbumId) (segments []PrioritySegment)
FindSegmentsBetweenAndFilter returns a list of segments between start and end date, only segments lead by the given albumId will be returned.
type TimelineAggregate ¶ added in v1.5.53
type TimelineAggregate struct {
// contains filtered or unexported fields
}
func NewTimelineAggregate ¶ added in v1.5.53
func NewTimelineAggregate(albums []*Album) (*TimelineAggregate, error)
NewTimelineAggregate builds a TimelineAggregate eagerly: the timeline is computed upfront so any inconsistency in the persisted albums (like a duplicated AlbumId) is surfaced immediately. Every mutating method on the aggregate keeps this invariant by rebuilding the timeline from the updated in-memory album list.
func (*TimelineAggregate) AmendDates ¶ added in v1.5.57
func (t *TimelineAggregate) AmendDates(albumId AlbumId, start, end time.Time) (*AlbumDatesUpdated, error)
AmendDates validates the amendment and, if the dates actually change, mutates the aggregate to reflect the new dates and computes the media transfer records plus any orphaned selectors. When the dates are unchanged, the aggregate is left untouched and the returned AlbumDatesUpdated has DatesUpdate.DatesNotChanged() == true and empty transfer records: it is up to the caller (the use case) to short-circuit on that signal.
Returns AlbumNotFoundErr if albumId is unknown to the aggregate.
func (*TimelineAggregate) CreateNewAlbum ¶ added in v1.5.54
func (t *TimelineAggregate) CreateNewAlbum(request CreateAlbumRequest) (Album, MediaTransferRecords, error)
CreateNewAlbum validates the request, appends the new album to the aggregate, rebuilds the timeline, and returns both the created Album and the MediaTransferRecords for medias that overlapping albums should hand over to it. Returns AlbumFolderNameAlreadyTakenErr if the computed folder name collides with an existing album.
func (*TimelineAggregate) FindAt ¶ added in v1.5.54
func (t *TimelineAggregate) FindAt(date time.Time) (*Album, bool)
func (*TimelineAggregate) RemoveAlbum ¶ added in v1.5.57
func (t *TimelineAggregate) RemoveAlbum(deletedAlbumId AlbumId) (MediaTransferRecords, []MediaSelector, error)
func (*TimelineAggregate) RenameAlbum ¶ added in v1.9.52
func (t *TimelineAggregate) RenameAlbum(request RenameAlbumRequest) (*AlbumNameUpdated, error)
RenameAlbum removes the existing album from the aggregate and inserts a new one carrying the new folder name / display name. It returns everything the application service needs to persist the rename and move the medias:
- AlbumNotFoundErr if currentId is unknown to the aggregate.
- AlbumFolderNameAlreadyTakenErr if the target folder name is used by another album.
The rename is expected to change the folder name; the caller is responsible for handling the name-only case (a simple UpdateAlbumName on the same row) before reaching this method.
type TimelineLookupStrategy ¶ added in v1.5.58
type TimelineLookupStrategy struct{}
func (TimelineLookupStrategy) LookupAlbum ¶ added in v1.5.58
func (t TimelineLookupStrategy) LookupAlbum(ctx context.Context, owner ownermodel.Owner, timeline *TimelineAggregate, mediaTime time.Time) (AlbumReference, error)
type TimelineMutationObserver ¶ added in v1.5.33
type TimelineMutationObserver interface {
OnTransferredMedias(ctx context.Context, transfers TransferredMedias) error
}
TimelineMutationObserver will notify each observer that medias has been transferred to a different album.
type TimelineMutationObserverFunc ¶ added in v1.5.42
type TimelineMutationObserverFunc func(ctx context.Context, transfers TransferredMedias) error
func (TimelineMutationObserverFunc) OnTransferredMedias ¶ added in v1.6.4
func (f TimelineMutationObserverFunc) OnTransferredMedias(ctx context.Context, transfers TransferredMedias) error
type TimelinePersistencePort ¶ added in v1.9.53
type TimelinePersistencePort interface {
FindAlbumsByOwner(ctx context.Context, owner ownermodel.Owner) ([]*Album, error)
InsertAlbum(ctx context.Context, album Album) error
DeleteAlbum(ctx context.Context, albumId AlbumId) error
UpdateAlbumName(ctx context.Context, albumId AlbumId, newName string) (Album, Album, error)
AmendDates(ctx context.Context, albumId AlbumId, start, end time.Time) error
}
TimelinePersistencePort is the persistence surface a TimelineRepositoryAdapter needs from the outside world. It is satisfied by the DynamoDB Repository as well as by the in-memory fake used in tests.
type TimelineRepository ¶ added in v1.9.53
type TimelineRepository interface {
LoadTimeline(ctx context.Context, owner ownermodel.Owner) (*TimelineAggregate, error)
InsertAlbum(ctx context.Context, album Album) error
DeleteAlbum(ctx context.Context, albumId AlbumId) error
UpdateAlbumName(ctx context.Context, albumId AlbumId, newName string) (Album, Album, error)
AmendDates(ctx context.Context, albumId AlbumId, start, end time.Time) error
}
TimelineRepository is the single port through which the album use cases both build the TimelineAggregate for an owner and persist mutations to individual albums. LoadTimeline returns a ready-to-use aggregate: it fails if the persisted albums cannot form a valid timeline (e.g. duplicated AlbumId).
type TimelineRepositoryAdapter ¶ added in v1.9.53
type TimelineRepositoryAdapter struct {
TimelinePersistencePort
}
TimelineRepositoryAdapter wraps a persistence adapter (typically the DynamoDB one) to satisfy the TimelineRepository port used by the album use cases. LoadTimeline reads the owner's albums and builds a TimelineAggregate eagerly; the write methods are inherited from the embedded adapter.
func (*TimelineRepositoryAdapter) LoadTimeline ¶ added in v1.9.53
func (t *TimelineRepositoryAdapter) LoadTimeline(ctx context.Context, owner ownermodel.Owner) (*TimelineAggregate, error)
type TransferMediasFromRepository ¶ added in v1.9.52
type TransferMediasFromRepository struct {
TransferMediasRepository TransferMediasRepositoryPort
}
TransferMediasFromRepository is the default TransferMediasService implementation: it delegates the actual move to the repository port and derives the FromAlbums list from the input records.
func (*TransferMediasFromRepository) TransferMedias ¶ added in v1.9.52
func (t *TransferMediasFromRepository) TransferMedias(ctx context.Context, records MediaTransferRecords) (TransferredMedias, error)
type TransferMediasFunc ¶ added in v1.5.41
type TransferMediasFunc func(ctx context.Context, records MediaTransferRecords) (map[AlbumId][]MediaId, error)
func (TransferMediasFunc) TransferMediasFromRecords ¶ added in v1.5.41
func (f TransferMediasFunc) TransferMediasFromRecords(ctx context.Context, records MediaTransferRecords) (map[AlbumId][]MediaId, error)
type TransferMediasRepositoryPort ¶ added in v1.5.45
type TransferMediasRepositoryPort interface {
TransferMediasFromRecords(ctx context.Context, records MediaTransferRecords) (map[AlbumId][]MediaId, error)
}
TransferMediasRepositoryPort moves the medias matched by records to their new album and returns, per destination album, the list of MediaIds that were actually moved.
type TransferMediasService ¶ added in v1.9.52
type TransferMediasService interface {
TransferMedias(ctx context.Context, records MediaTransferRecords) (TransferredMedias, error)
}
TransferMediasService is the internal domain service that moves medias between albums. It returns the destinations that were actually written along with the list of source albums the caller intended to pick medias from (derived from the input records).
type TransferredMedias ¶ added in v1.5.33
type TransferredMedias struct {
Transfers map[AlbumId][]MediaId
FromAlbums []AlbumId // FromAlbums is a list of potential origins of medias
}
TransferredMedias is a list of all medias that has be transferred to a different album in the state.
func NewTransferredMedias ¶ added in v1.6.4
func NewTransferredMedias() TransferredMedias
func (TransferredMedias) IsEmpty ¶ added in v1.5.41
func (t TransferredMedias) IsEmpty() bool
Source Files
¶
- album_amend_dates.go
- album_create.go
- album_create_request.go
- album_delete.go
- album_queries.go
- album_referencer.go
- album_rename.go
- album_transfer.go
- heaps.go
- media_id_codec.go
- medias_insert.go
- medias_insert_simulator.go
- medias_queries.go
- medias_queries_in_memory.go
- model_album.go
- model_filter.go
- model_media.go
- ports.go
- time_range.go
- timeline.go
- timeline_aggregate.go