try with writemodel

This commit is contained in:
adlerhurst
2020-11-18 21:22:15 +01:00
parent 147782332f
commit 4d6497f6c1
12 changed files with 232 additions and 67 deletions
+20 -10
View File
@@ -2,30 +2,40 @@ package idp
import "github.com/caos/zitadel/internal/eventstore/v2"
type AddedEvent struct {
type ConfigAddedEvent struct {
eventstore.BaseEvent
ID string `idpConfigId`
Name string `name`
ID string `json:"idpConfigId"`
Name string `json:"name"`
Type ConfigType `json:"idpType,omitempty"`
StylingType StylingType `json:"stylingType,omitempty"`
}
func NewAddedEvent(
base *eventstore.BaseEvent,
configID string,
name string,
) *AddedEvent {
configType ConfigType,
stylingType StylingType,
) *ConfigAddedEvent {
return &AddedEvent{
BaseEvent: *base,
ID: configID,
Name: name,
return &ConfigAddedEvent{
BaseEvent: *base,
ID: configID,
Name: name,
StylingType: stylingType,
Type: configType,
}
}
func (e *AddedEvent) CheckPrevious() bool {
func (e *ConfigAddedEvent) CheckPrevious() bool {
return true
}
func (e *AddedEvent) Data() interface{} {
func (e *ConfigAddedEvent) Data() interface{} {
return e
}
type ConfigType uint32
type StylingType uint32
+30 -14
View File
@@ -1,35 +1,51 @@
package idp
import "github.com/caos/zitadel/internal/eventstore/v2"
import (
"github.com/caos/zitadel/internal/errors"
"github.com/caos/zitadel/internal/eventstore/v2"
)
type ChangedEdvent struct {
type ConfigChangedEvent struct {
eventstore.BaseEvent `json:"-"`
current *ConfigAggregate
changed *ConfigAggregate
ID string `json:"idpConfigId"`
StylingType StylingType `json:"stylingType,omitempty"`
Name string `json:"name"`
hasChanged bool
}
func ChangedEvent(
func NewConfigChangedEvent(
base *eventstore.BaseEvent,
current *ConfigAggregate,
changed *ConfigAggregate,
) (*ChangedEdvent, error) {
//TODO: who to handle chanes?
) (*ConfigChangedEvent, error) {
return &ChangedEdvent{
change := &ConfigChangedEvent{
BaseEvent: *base,
current: current,
changed: changed,
}, nil
}
if current.ConfigID != changed.ConfigID {
change.ID = changed.ConfigID
change.hasChanged = true
}
if current.StylingType != changed.StylingType {
change.StylingType = changed.StylingType
change.hasChanged = true
}
if !change.hasChanged {
return nil, errors.ThrowPreconditionFailed(nil, "IDP-UBJbB", "Errors.NoChanges")
}
return change, nil
}
func (e *ChangedEdvent) CheckPrevious() bool {
func (e *ConfigChangedEvent) CheckPrevious() bool {
return true
}
func (e *ChangedEdvent) Data() interface{} {
func (e *ConfigChangedEvent) Data() interface{} {
if e.current.Name != e.changed.Name {
e.Name = e.changed.Name
}
+13 -1
View File
@@ -1,3 +1,15 @@
package oidc
type AddedEvent struct{}
import "github.com/caos/zitadel/internal/crypto"
type AddedEvent struct {
eventstore.BaseEvent
IDPConfigID string `json:"idpConfigId"`
ClientID string `json:"clientId"`
Secret *crypto.CryptoValue `json:"clientSecret"`
Issuer string `json:"issuer"`
Scopes []string `json:"scpoes"`
IDPDisplayNameMapping int32 `json:"idpDisplayNameMapping,omitempty"`
UsernameMapping int32 `json:"usernameMapping,omitempty"`
}