mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-14 20:08:02 +00:00
fbeab4c582
* feat: eventstore repository * fix: remove gorm * version * feat: pkg * feat: eventstore without eventstore-lib * rename files * gnueg * fix: add object * fix: global model * feat(eventstore): sdk * fix(eventstore): search query * fix(eventstore): rename app to eventstore * delete empty test * remove unused func * merge master * fix(eventstore): tests * fix(models): delete unused struct * feat(eventstore): implemented push events * feat(eventstore): overwrite context data * feat(types): SQL-config * feat(eventstore): options to overwrite editor * Update internal/eventstore/models/field.go Co-Authored-By: livio-a <livio.a@gmail.com> * fix(eventstore): code quality * fix(eventstore): rename modifier* to editor* * fix(eventstore): delete editor_org Co-authored-by: Fabiennne <fabienne.gerschwiler@gmail.com> Co-authored-by: livio-a <livio.a@gmail.com>
57 lines
1.2 KiB
Go
57 lines
1.2 KiB
Go
package models
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/caos/zitadel/internal/api/auth"
|
|
)
|
|
|
|
type AggregateCreator struct {
|
|
serviceName string
|
|
}
|
|
|
|
func NewAggregateCreator(serviceName string) *AggregateCreator {
|
|
return &AggregateCreator{serviceName: serviceName}
|
|
}
|
|
|
|
type option func(*Aggregate)
|
|
|
|
func (c *AggregateCreator) NewAggregate(ctx context.Context, id string, typ AggregateType, version Version, latestSequence uint64, opts ...option) (*Aggregate, error) {
|
|
ctxData := auth.GetCtxData(ctx)
|
|
editorUser := ctxData.UserID
|
|
resourceOwner := ctxData.OrgID
|
|
|
|
aggregate := &Aggregate{
|
|
id: id,
|
|
typ: typ,
|
|
latestSequence: latestSequence,
|
|
version: version,
|
|
Events: make([]*Event, 0, 2),
|
|
editorService: c.serviceName,
|
|
editorUser: editorUser,
|
|
resourceOwner: resourceOwner,
|
|
}
|
|
|
|
for _, opt := range opts {
|
|
opt(aggregate)
|
|
}
|
|
|
|
if err := aggregate.Validate(); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return aggregate, nil
|
|
}
|
|
|
|
func OverwriteEditorUser(userID string) func(*Aggregate) {
|
|
return func(a *Aggregate) {
|
|
a.editorUser = userID
|
|
}
|
|
}
|
|
|
|
func OverwriteResourceOwner(resourceOwner string) func(*Aggregate) {
|
|
return func(a *Aggregate) {
|
|
a.resourceOwner = resourceOwner
|
|
}
|
|
}
|