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.
- Asset Metadata:
This structure provides flexibility for managing diverse types of assets and their storage configurations.
Commands
- AssetCommandAdd
- AssetCommandRemove
- AssetCommandRemoveAttribute
- AssetCommandSetAttribute
- AssetCommandUpdate
AssetCommandAdd
Domain Command Struct:
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:
func (cs *commandHandler) AssetCommandAdd(ctx context.Context, cmd comby.Command, domainCmd *AssetCommandAdd) ([]comby.Event, error)
AssetCommandRemove
Domain Command Struct:
type AssetCommandRemove struct {
AssetUuid string `json:"assetUuid"`
}
Domain Command Handling Method:
func (cs *commandHandler) AssetCommandRemove(ctx context.Context, cmd comby.Command, domainCmd *AssetCommandRemove) ([]comby.Event, error)
AssetCommandRemoveAttribute
Domain Command Struct:
type AssetCommandRemoveAttribute struct {
AssetUuid string `json:"assetUuid"`
Key string `json:"key"`
}
Domain Command Handling Method:
func (cs *commandHandler) AssetCommandRemoveAttribute(ctx context.Context, cmd comby.Command, domainCmd *AssetCommandRemoveAttribute) ([]comby.Event, error)
AssetCommandSetAttribute
Domain Command Struct:
type AssetCommandSetAttribute struct {
AssetUuid string `json:"assetUuid"`
Key string `json:"key"`
Value any `json:"value"`
}
Domain Command Handling Method:
func (cs *commandHandler) AssetCommandSetAttribute(ctx context.Context, cmd comby.Command, domainCmd *AssetCommandSetAttribute) ([]comby.Event, error)
AssetCommandUpdate
Domain Command Struct:
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:
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:
type AssetQueryDownload struct {
AssetUuid string `json:"assetUuid"`
}
Domain Query Handling Method:
func (qs *queryHandler) AssetQueryDownload(ctx context.Context, qry comby.Query, domainQry *AssetQueryDownload) (*AssetQueryItemResponse, error)
AssetQueryList
Domain Query Struct:
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:
func (qs *queryHandler) AssetQueryList(ctx context.Context, qry comby.Query, domainQry *AssetQueryList) (*AssetQueryListResponse, error)
AssetQueryModelByBucketObject
Domain Query Struct:
type AssetQueryModelByBucketObject struct {
BucketName string `json:"bucketName"`
ObjectName string `json:"objectName"`
}
Domain Query Handling Method:
func (qs *queryHandler) AssetQueryModelByBucketObject(ctx context.Context, qry comby.Query, domainQry *AssetQueryModelByBucketObject) (*AssetQueryItemResponse, error)
AssetQueryModel
Domain Query Struct:
type AssetQueryModel struct {
AssetUuid string `json:"assetUuid"`
}
Domain Query Handling Method:
func (qs *queryHandler) AssetQueryModel(ctx context.Context, qry comby.Query, domainQry *AssetQueryModel) (*AssetQueryItemResponse, error)
AssetQueryItemResponse
type AssetQueryItemResponse struct {
Item *readmodel.AssetModel `json:"item,omitempty"`
}
AssetQueryListResponse
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:
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:
func (agg *Asset) AssetAddedEvent(ctx context.Context, evt comby.Event, domainEvt *AssetAddedEvent) (error)
AssetRemovedEvent
Domain Event Struct:
type AssetRemovedEvent struct {
Reason string `json:"reason,omitempty"`
}
Domain Event Handling Method:
func (agg *Asset) AssetRemovedEvent(ctx context.Context, evt comby.Event, domainEvt *AssetRemovedEvent) (error)
AssetAttributeRemovedEvent
Domain Event Struct:
type AssetAttributeRemovedEvent struct {
Key string `json:"key"`
}
Domain Event Handling Method:
func (agg *Asset) AssetAttributeRemovedEvent(ctx context.Context, evt comby.Event, domainEvt *AssetAttributeRemovedEvent) (error)
AssetAttributeSetEvent
Domain Event Struct:
type AssetAttributeSetEvent struct {
Key string `json:"key"`
Value any `json:"value"`
}
Domain Event Handling Method:
func (agg *Asset) AssetAttributeSetEvent(ctx context.Context, evt comby.Event, domainEvt *AssetAttributeSetEvent) (error)
AssetUpdatedEvent
Domain Event Struct:
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:
func (agg *Asset) AssetUpdatedEvent(ctx context.Context, evt comby.Event, domainEvt *AssetUpdatedEvent) (error)
Aggregate
Aggregate Struct:
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
func (agg *Asset) Add(identityUuid, assetName string, assetSize int64, assetContentType, bucketName, objectName, attributes string) (error)
Remove
func (agg *Asset) Remove() (error)
RemoveAttribute
func (agg *Asset) RemoveAttribute(key string) (error)
SetAttribute
func (agg *Asset) SetAttribute(key string, value any) (error)
Update
func (agg *Asset) Update(identityUuid, assetName string, assetSize int64, assetContentType, bucketName, objectName, attributes string) (error)
Event Handlers
AssetReadmodel
Domain Event | Method |
---|---|
tenantAggregate.TenantCreatedEvent | TenantCreatedEvent |
tenantAggregate.TenantRemovedEvent | TenantRemovedEvent |
tenantAggregate.TenantUpdatedEvent | TenantUpdatedEvent |
identityAggregate.IdentityCreatedEvent | IdentityCreatedEvent |
identityAggregate.IdentityProfileUpdatedEvent | IdentityProfileUpdatedEvent |
identityAggregate.IdentityRemovedEvent | IdentityRemovedEvent |
assetAggregate.AssetAddedEvent | AssetAddedEvent |
assetAggregate.AssetUpdatedEvent | AssetUpdatedEvent |
assetAggregate.AssetRemovedEvent | AssetRemovedEvent |
assetAggregate.AssetAttributeSetEvent | AssetAttributeSetEvent |
assetAggregate.AssetAttributeRemovedEvent | AssetAttributeRemovedEvent |
Custom Permissions
Name | Type | Comment |
---|---|---|
AssetCommandAdd | Command | Create and upload asset |
AssetCommandRemove | Command | Remove existing asset |
AssetCommandUpdate | Command | Update existing asset |
AssetCommandSetAttribute | Command | Set single attribute for existing asset |
AssetCommandRemoveAttribute | Command | Remove single attribute from existing asset |
AssetQueryDownload | Query | Download existing asset |
AssetQueryList | Query | List all assets |
AssetQueryModel | Query | Get asset |
AssetQueryModelByBucketObject | Query | Get asset by bucket and object name |