Skip to content

Asset

Overview

The Asset domain in comby is designed to manage digital assets, such as files, documents, or media, along with their associated metadata and storage information. It provides a structured framework for tracking asset lifecycle events, including creation, updates, and removal. The Asset aggregate is at the core of this domain, encapsulating the properties and behaviors of assets while maintaining consistency through event sourcing.

Structure

The Asset aggregate extends the BaseAggregate, leveraging comby's event-sourcing capabilities for managing state and tracking changes. It defines several fields to represent asset-specific and storage-related attributes:

  • References:
    • IdentityUuid: Links the asset to the identity that owns or created it.
  • Entities: Reserved for nested data structures (not included in the default implementation).
  • Value Objects:
    • Asset Metadata:
      • Name: The name of the asset.
      • Size: The size of the asset in bytes.
      • ContentType: The MIME type of the asset (e.g., image/png, application/pdf).
      • Path: The logical or relative path of the asset.
    • Storage Metadata:
      • BucketName: The storage bucket where the asset is stored.
      • ObjectName: The unique identifier for the asset in the storage system.
    • Tags: A list of tags for categorizing or labeling the asset.
    • Public: A boolean indicating whether the asset is publicly accessible.
    • Additionals: A map for storing custom metadata or additional attributes.

This structure provides flexibility for managing diverse types of assets and their storage configurations.

Commands

AssetCommandAdd

Domain Command Struct:

go
type AssetCommandAdd struct {
	AssetUuid        string `json:"assetUuid"`
	IdentityUuid     string `json:"identityUuid,omitempty"`
	AssetName        string `json:"assetName,omitempty"`
	AssetSize        int64  `json:"assetSize,omitempty"`
	AssetContentType string `json:"assetContentType,omitempty"`
	Attributes       string `json:"attributes,omitempty"`
}

Domain Command Handling Method:

go
func (cs *commandHandler) AssetCommandAdd(ctx context.Context, cmd comby.Command, domainCmd *AssetCommandAdd) ([]comby.Event, error)

AssetCommandRemove

Domain Command Struct:

go
type AssetCommandRemove struct {
	AssetUuid string `json:"assetUuid"`
}

Domain Command Handling Method:

go
func (cs *commandHandler) AssetCommandRemove(ctx context.Context, cmd comby.Command, domainCmd *AssetCommandRemove) ([]comby.Event, error)

AssetCommandRemoveAttribute

Domain Command Struct:

go
type AssetCommandRemoveAttribute struct {
	AssetUuid string `json:"assetUuid"`
	Key       string `json:"key"`
}

Domain Command Handling Method:

go
func (cs *commandHandler) AssetCommandRemoveAttribute(ctx context.Context, cmd comby.Command, domainCmd *AssetCommandRemoveAttribute) ([]comby.Event, error)

AssetCommandSetAttribute

Domain Command Struct:

go
type AssetCommandSetAttribute struct {
	AssetUuid string `json:"assetUuid"`
	Key       string `json:"key"`
	Value     any    `json:"value"`
}

Domain Command Handling Method:

go
func (cs *commandHandler) AssetCommandSetAttribute(ctx context.Context, cmd comby.Command, domainCmd *AssetCommandSetAttribute) ([]comby.Event, error)

AssetCommandUpdate

Domain Command Struct:

go
type AssetCommandUpdate struct {
	IdentityUuid     string   `json:"identityUuid"`
	AssetUuid        string   `json:"assetUuid"`
	AssetName        string   `json:"assetName,omitempty"`
	AssetSize        int64    `json:"assetSize,omitempty"`
	AssetContentType string   `json:"assetContentType,omitempty"`
	Attributes       string   `json:"attributes,omitempty"`
	PatchedFields    []string `json:"patchedFields"`
}

Domain Command Handling Method:

go
func (cs *commandHandler) AssetCommandUpdate(ctx context.Context, cmd comby.Command, domainCmd *AssetCommandUpdate) ([]comby.Event, error)

Queries

Domain Query Structs:

Domain Query Responses:

AssetQueryDownload

Domain Query Struct:

go
type AssetQueryDownload struct {
	AssetUuid string `json:"assetUuid"`
}

Domain Query Handling Method:

go
func (qs *queryHandler) AssetQueryDownload(ctx context.Context, qry comby.Query, domainQry *AssetQueryDownload) (*AssetQueryItemResponse, error)

AssetQueryList

Domain Query Struct:

go
type AssetQueryList struct {
	TenantUuid string `json:"tenantUuid"`
	Page       int64  `json:"page,omitempty"`
	PageSize   int64  `json:"pageSize,omitempty"`
	OrderBy    string `json:"orderBy,omitempty"`
	Attributes string `json:"attributes,omitempty"`
}

Domain Query Handling Method:

go
func (qs *queryHandler) AssetQueryList(ctx context.Context, qry comby.Query, domainQry *AssetQueryList) (*AssetQueryListResponse, error)

AssetQueryModelByBucketObject

Domain Query Struct:

go
type AssetQueryModelByBucketObject struct {
	BucketName string `json:"bucketName"`
	ObjectName string `json:"objectName"`
}

Domain Query Handling Method:

go
func (qs *queryHandler) AssetQueryModelByBucketObject(ctx context.Context, qry comby.Query, domainQry *AssetQueryModelByBucketObject) (*AssetQueryItemResponse, error)

AssetQueryModel

Domain Query Struct:

go
type AssetQueryModel struct {
	AssetUuid string `json:"assetUuid"`
}

Domain Query Handling Method:

go
func (qs *queryHandler) AssetQueryModel(ctx context.Context, qry comby.Query, domainQry *AssetQueryModel) (*AssetQueryItemResponse, error)

AssetQueryItemResponse

go
type AssetQueryItemResponse struct {
	Item *readmodel.AssetModel `json:"item,omitempty"`
}

AssetQueryListResponse

go
type AssetQueryListResponse struct {
	Items    []*readmodel.AssetModel `json:"items,omitempty"`
	Total    int64                   `json:"total,omitempty"`
	Page     int64                   `json:"page,omitempty"`
	PageSize int64                   `json:"pageSize,omitempty"`
}

Events

AssetAddedEvent

Domain Event Struct:

go
type AssetAddedEvent struct {
	IdentityUuid     string `json:"identityUuid,omitempty"`
	AssetName        string `json:"assetName,omitempty"`
	AssetSize        int64  `json:"assetSize,omitempty"`
	AssetContentType string `json:"assetContentType,omitempty"`
	BucketName       string `json:"bucketName,omitempty"`
	ObjectName       string `json:"objectName,omitempty"`
	Attributes       string `json:"attributes,omitempty"`
}

Domain Event Handling Method:

go
func (agg *Asset) AssetAddedEvent(ctx context.Context, evt comby.Event, domainEvt *AssetAddedEvent) (error)

AssetRemovedEvent

Domain Event Struct:

go
type AssetRemovedEvent struct {
	Reason string `json:"reason,omitempty"`
}

Domain Event Handling Method:

go
func (agg *Asset) AssetRemovedEvent(ctx context.Context, evt comby.Event, domainEvt *AssetRemovedEvent) (error)

AssetAttributeRemovedEvent

Domain Event Struct:

go
type AssetAttributeRemovedEvent struct {
	Key string `json:"key"`
}

Domain Event Handling Method:

go
func (agg *Asset) AssetAttributeRemovedEvent(ctx context.Context, evt comby.Event, domainEvt *AssetAttributeRemovedEvent) (error)

AssetAttributeSetEvent

Domain Event Struct:

go
type AssetAttributeSetEvent struct {
	Key   string `json:"key"`
	Value any    `json:"value"`
}

Domain Event Handling Method:

go
func (agg *Asset) AssetAttributeSetEvent(ctx context.Context, evt comby.Event, domainEvt *AssetAttributeSetEvent) (error)

AssetUpdatedEvent

Domain Event Struct:

go
type AssetUpdatedEvent struct {
	IdentityUuid     string `json:"identityUuid,omitempty"`
	AssetName        string `json:"assetName,omitempty"`
	AssetSize        int64  `json:"assetSize,omitempty"`
	AssetContentType string `json:"assetContentType,omitempty"`
	BucketName       string `json:"bucketName,omitempty"`
	ObjectName       string `json:"objectName,omitempty"`
	Attributes       string `json:"attributes,omitempty"`
}

Domain Event Handling Method:

go
func (agg *Asset) AssetUpdatedEvent(ctx context.Context, evt comby.Event, domainEvt *AssetUpdatedEvent) (error)

Aggregate

Aggregate Struct:

go
type Asset struct {
	*comby.BaseAggregate
	// References
	IdentityUuid string
	// Value Objects (asset)
	Name        string
	Size        int64
	ContentType string
	Path        string
	// Value Objects (storage)
	BucketName string
	ObjectName string
}

Methods

Add

go
func (agg *Asset) Add(identityUuid, assetName string, assetSize int64, assetContentType, bucketName, objectName, attributes string) (error)

Remove

go
func (agg *Asset) Remove() (error)

RemoveAttribute

go
func (agg *Asset) RemoveAttribute(key string) (error)

SetAttribute

go
func (agg *Asset) SetAttribute(key string, value any) (error)

Update

go
func (agg *Asset) Update(identityUuid, assetName string, assetSize int64, assetContentType, bucketName, objectName, attributes string) (error)

Event Handlers

AssetReadmodel

Domain EventMethod
tenantAggregate.TenantCreatedEventTenantCreatedEvent
tenantAggregate.TenantRemovedEventTenantRemovedEvent
tenantAggregate.TenantUpdatedEventTenantUpdatedEvent
identityAggregate.IdentityCreatedEventIdentityCreatedEvent
identityAggregate.IdentityProfileUpdatedEventIdentityProfileUpdatedEvent
identityAggregate.IdentityRemovedEventIdentityRemovedEvent
assetAggregate.AssetAddedEventAssetAddedEvent
assetAggregate.AssetUpdatedEventAssetUpdatedEvent
assetAggregate.AssetRemovedEventAssetRemovedEvent
assetAggregate.AssetAttributeSetEventAssetAttributeSetEvent
assetAggregate.AssetAttributeRemovedEventAssetAttributeRemovedEvent

Custom Permissions

NameTypeComment
AssetCommandAddCommandCreate and upload asset
AssetCommandRemoveCommandRemove existing asset
AssetCommandUpdateCommandUpdate existing asset
AssetCommandSetAttributeCommandSet single attribute for existing asset
AssetCommandRemoveAttributeCommandRemove single attribute from existing asset
AssetQueryDownloadQueryDownload existing asset
AssetQueryListQueryList all assets
AssetQueryModelQueryGet asset
AssetQueryModelByBucketObjectQueryGet asset by bucket and object name