mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-14 03:54:21 +00:00
f680dd934d
* chore: rename package errors to zerrors * rename package errors to gerrors * fix error related linting issues * fix zitadel error assertion * fix gosimple linting issues * fix deprecated linting issues * resolve gci linting issues * fix import structure --------- Co-authored-by: Elio Bischof <elio@zitadel.com>
88 lines
1.6 KiB
Go
88 lines
1.6 KiB
Go
package asset
|
|
|
|
import (
|
|
"github.com/zitadel/zitadel/internal/eventstore"
|
|
"github.com/zitadel/zitadel/internal/zerrors"
|
|
)
|
|
|
|
const (
|
|
AddedEventType = "asset.added"
|
|
RemovedEventType = "asset.removed"
|
|
)
|
|
|
|
type AddedEvent struct {
|
|
eventstore.BaseEvent `json:"-"`
|
|
|
|
StoreKey string `json:"storeKey"`
|
|
}
|
|
|
|
func (e *AddedEvent) Payload() interface{} {
|
|
return e
|
|
}
|
|
|
|
func (e *AddedEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
|
|
return nil
|
|
}
|
|
|
|
func NewAddedEvent(
|
|
base *eventstore.BaseEvent,
|
|
key string,
|
|
) *AddedEvent {
|
|
|
|
return &AddedEvent{
|
|
BaseEvent: *base,
|
|
StoreKey: key,
|
|
}
|
|
}
|
|
|
|
func AddedEventMapper(event eventstore.Event) (eventstore.Event, error) {
|
|
e := &AddedEvent{
|
|
BaseEvent: *eventstore.BaseEventFromRepo(event),
|
|
}
|
|
|
|
err := event.Unmarshal(e)
|
|
if err != nil {
|
|
return nil, zerrors.ThrowInternal(err, "ASSET-1WEAx", "unable to unmarshal asset")
|
|
}
|
|
|
|
return e, nil
|
|
}
|
|
|
|
type RemovedEvent struct {
|
|
eventstore.BaseEvent `json:"-"`
|
|
|
|
StoreKey string `json:"storeKey"`
|
|
}
|
|
|
|
func (e *RemovedEvent) Payload() interface{} {
|
|
return e
|
|
}
|
|
|
|
func (e *RemovedEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
|
|
return nil
|
|
}
|
|
|
|
func NewRemovedEvent(
|
|
base *eventstore.BaseEvent,
|
|
key string,
|
|
) *RemovedEvent {
|
|
|
|
return &RemovedEvent{
|
|
BaseEvent: *base,
|
|
StoreKey: key,
|
|
}
|
|
}
|
|
|
|
func RemovedEventMapper(event eventstore.Event) (eventstore.Event, error) {
|
|
e := &RemovedEvent{
|
|
BaseEvent: *eventstore.BaseEventFromRepo(event),
|
|
}
|
|
|
|
err := event.Unmarshal(e)
|
|
if err != nil {
|
|
return nil, zerrors.ThrowInternal(err, "ASSET-1m9PP", "unable to unmarshal asset")
|
|
}
|
|
|
|
return e, nil
|
|
}
|