1
0
mirror of https://github.com/zitadel/zitadel.git synced 2025-08-13 06:07:46 +00:00
Files
.codecov
.github
build
cmd
console
docs
guides
hack
internal
admin
api
auth
auth_request
authz
cache
command
config
crypto
domain
errors
eventstore
playground
repository
v1
aggregate.go
asset.go
config.go
event.go
event_base.go
eventstore.go
eventstore_test.go
example_test.go
local_crdb_test.go
read_model.go
search_query.go
search_query_test.go
subscription.go
unique_constraint.go
version.go
write_model.go
features
form
i18n
iam
id
key
management
notification
org
project
proto
protoc
qrcode
query
renderer
repository
setup
static
statik
telemetry
test
ui
user
usergrant
view
webauthn
k8s
migrations
openapi
operator
pkg
proto
scripts
statik
tools
.dockerignore
.gitignore
.releaserc.js
CODE_OF_CONDUCT.md
CONTRIBUTING.md
LICENSE
README.md
SECURITY.md
changelog.config.js
go.mod
go.sum
zitadel/internal/eventstore/event_base.go

92 lines
2.4 KiB
Go
Raw Normal View History

2020-11-06 13:47:27 +01:00
package eventstore
import (
2020-11-06 17:25:07 +01:00
"context"
2020-11-06 13:47:27 +01:00
"time"
2020-11-06 17:25:07 +01:00
"github.com/caos/zitadel/internal/api/authz"
2020-11-06 22:09:19 +01:00
"github.com/caos/zitadel/internal/api/service"
"github.com/caos/zitadel/internal/eventstore/repository"
2020-11-06 13:47:27 +01:00
)
//BaseEvent represents the minimum metadata of an event
2020-11-06 13:47:27 +01:00
type BaseEvent struct {
EventType EventType
2020-11-06 13:47:27 +01:00
aggregate Aggregate
sequence uint64
creationDate time.Time
2020-11-06 13:47:27 +01:00
//User is the user who created the event
User string `json:"-"`
//Service is the service which created the event
Service string `json:"-"`
Data []byte `json:"-"`
2020-11-06 13:47:27 +01:00
}
// EditorService implements EventPusher
func (e *BaseEvent) EditorService() string {
return e.Service
}
//EditorUser implements EventPusher
func (e *BaseEvent) EditorUser() string {
return e.User
}
//Type implements EventPusher
2020-11-06 13:47:27 +01:00
func (e *BaseEvent) Type() EventType {
return e.EventType
}
//Sequence is an upcounting unique number of the event
2020-11-06 13:47:27 +01:00
func (e *BaseEvent) Sequence() uint64 {
return e.sequence
}
//CreationDate is the the time, the event is inserted into the eventstore
2020-11-06 13:47:27 +01:00
func (e *BaseEvent) CreationDate() time.Time {
return e.creationDate
}
//Aggregate represents the metadata of the event's aggregate
func (e *BaseEvent) Aggregate() Aggregate {
return e.aggregate
}
//Data returns the payload of the event. It represent the changed fields by the event
func (e *BaseEvent) DataAsBytes() []byte {
return e.Data
}
//BaseEventFromRepo maps a stored event to a BaseEvent
2020-11-06 13:47:27 +01:00
func BaseEventFromRepo(event *repository.Event) *BaseEvent {
return &BaseEvent{
aggregate: Aggregate{
ID: event.AggregateID,
Typ: AggregateType(event.AggregateType),
ResourceOwner: event.ResourceOwner,
Version: Version(event.Version),
},
EventType: EventType(event.Type),
creationDate: event.CreationDate,
sequence: event.Sequence,
Service: event.EditorService,
User: event.EditorUser,
Data: event.Data,
2020-11-06 13:47:27 +01:00
}
}
//NewBaseEventForPush is the constructor for event's which will be pushed into the eventstore
// the resource owner of the aggregate is only used if it's the first event of this aggregateroot
// afterwards the resource owner of the first previous events is taken
func NewBaseEventForPush(ctx context.Context, aggregate *Aggregate, typ EventType) *BaseEvent {
2020-11-06 17:25:07 +01:00
return &BaseEvent{
aggregate: *aggregate,
2020-11-06 17:25:07 +01:00
User: authz.GetCtxData(ctx).UserID,
Service: service.FromContext(ctx),
2020-11-06 17:25:07 +01:00
EventType: typ,
}
}