2021-11-30 07:57:51 +00:00
|
|
|
package projection
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"database/sql"
|
|
|
|
|
2022-04-26 23:01:45 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/domain"
|
|
|
|
"github.com/zitadel/zitadel/internal/eventstore"
|
2023-10-19 10:19:10 +00:00
|
|
|
old_handler "github.com/zitadel/zitadel/internal/eventstore/handler"
|
|
|
|
"github.com/zitadel/zitadel/internal/eventstore/handler/v2"
|
2022-10-20 12:36:52 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/repository/instance"
|
2022-11-30 16:01:17 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/repository/org"
|
2022-04-26 23:01:45 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/repository/user"
|
2023-12-08 14:30:55 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/zerrors"
|
2021-11-30 07:57:51 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2023-12-05 17:01:03 +00:00
|
|
|
UserTable = "projections.users10"
|
2021-11-30 07:57:51 +00:00
|
|
|
UserHumanTable = UserTable + "_" + UserHumanSuffix
|
|
|
|
UserMachineTable = UserTable + "_" + UserMachineSuffix
|
2022-07-06 12:09:49 +00:00
|
|
|
UserNotifyTable = UserTable + "_" + UserNotifySuffix
|
2021-11-30 07:57:51 +00:00
|
|
|
|
|
|
|
UserIDCol = "id"
|
|
|
|
UserCreationDateCol = "creation_date"
|
|
|
|
UserChangeDateCol = "change_date"
|
|
|
|
UserSequenceCol = "sequence"
|
2022-03-23 08:02:39 +00:00
|
|
|
UserStateCol = "state"
|
|
|
|
UserResourceOwnerCol = "resource_owner"
|
|
|
|
UserInstanceIDCol = "instance_id"
|
2021-11-30 07:57:51 +00:00
|
|
|
UserUsernameCol = "username"
|
2022-01-14 09:45:50 +00:00
|
|
|
UserTypeCol = "type"
|
2021-11-30 07:57:51 +00:00
|
|
|
|
2022-05-25 12:15:13 +00:00
|
|
|
UserHumanSuffix = "humans"
|
|
|
|
HumanUserIDCol = "user_id"
|
|
|
|
HumanUserInstanceIDCol = "instance_id"
|
2021-11-30 07:57:51 +00:00
|
|
|
|
|
|
|
// profile
|
2021-12-14 07:19:02 +00:00
|
|
|
HumanFirstNameCol = "first_name"
|
2021-11-30 07:57:51 +00:00
|
|
|
HumanLastNameCol = "last_name"
|
|
|
|
HumanNickNameCol = "nick_name"
|
|
|
|
HumanDisplayNameCol = "display_name"
|
|
|
|
HumanPreferredLanguageCol = "preferred_language"
|
|
|
|
HumanGenderCol = "gender"
|
2022-01-20 14:40:25 +00:00
|
|
|
HumanAvatarURLCol = "avatar_key"
|
2021-11-30 07:57:51 +00:00
|
|
|
|
|
|
|
// email
|
|
|
|
HumanEmailCol = "email"
|
|
|
|
HumanIsEmailVerifiedCol = "is_email_verified"
|
|
|
|
|
|
|
|
// phone
|
|
|
|
HumanPhoneCol = "phone"
|
|
|
|
HumanIsPhoneVerifiedCol = "is_phone_verified"
|
|
|
|
|
2022-03-23 08:02:39 +00:00
|
|
|
// machine
|
2023-02-08 08:06:34 +00:00
|
|
|
UserMachineSuffix = "machines"
|
|
|
|
MachineUserIDCol = "user_id"
|
|
|
|
MachineUserInstanceIDCol = "instance_id"
|
|
|
|
MachineNameCol = "name"
|
|
|
|
MachineDescriptionCol = "description"
|
2023-12-05 17:01:03 +00:00
|
|
|
MachineSecretCol = "secret"
|
2023-02-08 08:06:34 +00:00
|
|
|
MachineAccessTokenTypeCol = "access_token_type"
|
2022-07-06 12:09:49 +00:00
|
|
|
|
|
|
|
// notify
|
2024-03-20 15:51:26 +00:00
|
|
|
UserNotifySuffix = "notifications"
|
|
|
|
NotifyUserIDCol = "user_id"
|
|
|
|
NotifyInstanceIDCol = "instance_id"
|
|
|
|
NotifyLastEmailCol = "last_email"
|
|
|
|
NotifyVerifiedEmailCol = "verified_email"
|
|
|
|
NotifyVerifiedEmailLowerCol = "verified_email_lower"
|
|
|
|
NotifyLastPhoneCol = "last_phone"
|
|
|
|
NotifyVerifiedPhoneCol = "verified_phone"
|
|
|
|
NotifyPasswordSetCol = "password_set"
|
2021-11-30 07:57:51 +00:00
|
|
|
)
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
type userProjection struct{}
|
|
|
|
|
|
|
|
func newUserProjection(ctx context.Context, config handler.Config) *handler.Handler {
|
|
|
|
return handler.NewHandler(ctx, &config, new(userProjection))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (*userProjection) Name() string {
|
|
|
|
return UserTable
|
|
|
|
}
|
|
|
|
|
|
|
|
func (*userProjection) Init() *old_handler.Check {
|
|
|
|
return handler.NewMultiTableCheck(
|
|
|
|
handler.NewTable([]*handler.InitColumn{
|
|
|
|
handler.NewColumn(UserIDCol, handler.ColumnTypeText),
|
|
|
|
handler.NewColumn(UserCreationDateCol, handler.ColumnTypeTimestamp),
|
|
|
|
handler.NewColumn(UserChangeDateCol, handler.ColumnTypeTimestamp),
|
|
|
|
handler.NewColumn(UserSequenceCol, handler.ColumnTypeInt64),
|
|
|
|
handler.NewColumn(UserStateCol, handler.ColumnTypeEnum),
|
|
|
|
handler.NewColumn(UserResourceOwnerCol, handler.ColumnTypeText),
|
|
|
|
handler.NewColumn(UserInstanceIDCol, handler.ColumnTypeText),
|
|
|
|
handler.NewColumn(UserUsernameCol, handler.ColumnTypeText),
|
|
|
|
handler.NewColumn(UserTypeCol, handler.ColumnTypeEnum),
|
2022-03-23 08:02:39 +00:00
|
|
|
},
|
2023-10-19 10:19:10 +00:00
|
|
|
handler.NewPrimaryKey(UserInstanceIDCol, UserIDCol),
|
|
|
|
handler.WithIndex(handler.NewIndex("username", []string{UserUsernameCol})),
|
|
|
|
handler.WithIndex(handler.NewIndex("resource_owner", []string{UserResourceOwnerCol})),
|
2022-03-23 08:02:39 +00:00
|
|
|
),
|
2023-10-19 10:19:10 +00:00
|
|
|
handler.NewSuffixedTable([]*handler.InitColumn{
|
|
|
|
handler.NewColumn(HumanUserIDCol, handler.ColumnTypeText),
|
|
|
|
handler.NewColumn(HumanUserInstanceIDCol, handler.ColumnTypeText),
|
|
|
|
handler.NewColumn(HumanFirstNameCol, handler.ColumnTypeText),
|
|
|
|
handler.NewColumn(HumanLastNameCol, handler.ColumnTypeText),
|
|
|
|
handler.NewColumn(HumanNickNameCol, handler.ColumnTypeText, handler.Nullable()),
|
|
|
|
handler.NewColumn(HumanDisplayNameCol, handler.ColumnTypeText, handler.Nullable()),
|
|
|
|
handler.NewColumn(HumanPreferredLanguageCol, handler.ColumnTypeText, handler.Nullable()),
|
|
|
|
handler.NewColumn(HumanGenderCol, handler.ColumnTypeEnum, handler.Nullable()),
|
|
|
|
handler.NewColumn(HumanAvatarURLCol, handler.ColumnTypeText, handler.Nullable()),
|
|
|
|
handler.NewColumn(HumanEmailCol, handler.ColumnTypeText),
|
|
|
|
handler.NewColumn(HumanIsEmailVerifiedCol, handler.ColumnTypeBool, handler.Default(false)),
|
|
|
|
handler.NewColumn(HumanPhoneCol, handler.ColumnTypeText, handler.Nullable()),
|
|
|
|
handler.NewColumn(HumanIsPhoneVerifiedCol, handler.ColumnTypeBool, handler.Nullable()),
|
2022-03-23 08:02:39 +00:00
|
|
|
},
|
2023-10-19 10:19:10 +00:00
|
|
|
handler.NewPrimaryKey(HumanUserInstanceIDCol, HumanUserIDCol),
|
2022-03-23 08:02:39 +00:00
|
|
|
UserHumanSuffix,
|
2023-10-19 10:19:10 +00:00
|
|
|
handler.WithForeignKey(handler.NewForeignKeyOfPublicKeys()),
|
2022-03-23 08:02:39 +00:00
|
|
|
),
|
2023-10-19 10:19:10 +00:00
|
|
|
handler.NewSuffixedTable([]*handler.InitColumn{
|
|
|
|
handler.NewColumn(MachineUserIDCol, handler.ColumnTypeText),
|
|
|
|
handler.NewColumn(MachineUserInstanceIDCol, handler.ColumnTypeText),
|
|
|
|
handler.NewColumn(MachineNameCol, handler.ColumnTypeText),
|
|
|
|
handler.NewColumn(MachineDescriptionCol, handler.ColumnTypeText, handler.Nullable()),
|
2023-12-05 17:01:03 +00:00
|
|
|
handler.NewColumn(MachineSecretCol, handler.ColumnTypeJSONB, handler.Nullable()),
|
2023-10-19 10:19:10 +00:00
|
|
|
handler.NewColumn(MachineAccessTokenTypeCol, handler.ColumnTypeEnum, handler.Default(0)),
|
2022-03-23 08:02:39 +00:00
|
|
|
},
|
2023-10-19 10:19:10 +00:00
|
|
|
handler.NewPrimaryKey(MachineUserInstanceIDCol, MachineUserIDCol),
|
2022-03-23 08:02:39 +00:00
|
|
|
UserMachineSuffix,
|
2023-10-19 10:19:10 +00:00
|
|
|
handler.WithForeignKey(handler.NewForeignKeyOfPublicKeys()),
|
2022-03-23 08:02:39 +00:00
|
|
|
),
|
2023-10-19 10:19:10 +00:00
|
|
|
handler.NewSuffixedTable([]*handler.InitColumn{
|
|
|
|
handler.NewColumn(NotifyUserIDCol, handler.ColumnTypeText),
|
|
|
|
handler.NewColumn(NotifyInstanceIDCol, handler.ColumnTypeText),
|
|
|
|
handler.NewColumn(NotifyLastEmailCol, handler.ColumnTypeText, handler.Nullable()),
|
|
|
|
handler.NewColumn(NotifyVerifiedEmailCol, handler.ColumnTypeText, handler.Nullable()),
|
|
|
|
handler.NewColumn(NotifyLastPhoneCol, handler.ColumnTypeText, handler.Nullable()),
|
|
|
|
handler.NewColumn(NotifyVerifiedPhoneCol, handler.ColumnTypeText, handler.Nullable()),
|
|
|
|
handler.NewColumn(NotifyPasswordSetCol, handler.ColumnTypeBool, handler.Default(false)),
|
2022-07-06 12:09:49 +00:00
|
|
|
},
|
2023-10-19 10:19:10 +00:00
|
|
|
handler.NewPrimaryKey(NotifyInstanceIDCol, NotifyUserIDCol),
|
2022-07-06 12:09:49 +00:00
|
|
|
UserNotifySuffix,
|
2023-10-19 10:19:10 +00:00
|
|
|
handler.WithForeignKey(handler.NewForeignKeyOfPublicKeys()),
|
2022-07-06 12:09:49 +00:00
|
|
|
),
|
2022-03-23 08:02:39 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func (p *userProjection) Reducers() []handler.AggregateReducer {
|
2021-11-30 07:57:51 +00:00
|
|
|
return []handler.AggregateReducer{
|
|
|
|
{
|
|
|
|
Aggregate: user.AggregateType,
|
2023-10-19 10:19:10 +00:00
|
|
|
EventReducers: []handler.EventReducer{
|
2021-11-30 07:57:51 +00:00
|
|
|
{
|
|
|
|
Event: user.UserV1AddedType,
|
|
|
|
Reduce: p.reduceHumanAdded,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Event: user.HumanAddedType,
|
|
|
|
Reduce: p.reduceHumanAdded,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Event: user.UserV1RegisteredType,
|
|
|
|
Reduce: p.reduceHumanRegistered,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Event: user.HumanRegisteredType,
|
|
|
|
Reduce: p.reduceHumanRegistered,
|
|
|
|
},
|
2022-01-25 10:35:38 +00:00
|
|
|
{
|
|
|
|
Event: user.HumanInitialCodeAddedType,
|
|
|
|
Reduce: p.reduceHumanInitCodeAdded,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Event: user.UserV1InitialCodeAddedType,
|
|
|
|
Reduce: p.reduceHumanInitCodeAdded,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Event: user.HumanInitializedCheckSucceededType,
|
|
|
|
Reduce: p.reduceHumanInitCodeSucceeded,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Event: user.UserV1InitializedCheckSucceededType,
|
|
|
|
Reduce: p.reduceHumanInitCodeSucceeded,
|
|
|
|
},
|
2021-11-30 07:57:51 +00:00
|
|
|
{
|
|
|
|
Event: user.UserLockedType,
|
|
|
|
Reduce: p.reduceUserLocked,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Event: user.UserUnlockedType,
|
|
|
|
Reduce: p.reduceUserUnlocked,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Event: user.UserDeactivatedType,
|
|
|
|
Reduce: p.reduceUserDeactivated,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Event: user.UserReactivatedType,
|
|
|
|
Reduce: p.reduceUserReactivated,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Event: user.UserRemovedType,
|
|
|
|
Reduce: p.reduceUserRemoved,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Event: user.UserUserNameChangedType,
|
|
|
|
Reduce: p.reduceUserNameChanged,
|
|
|
|
},
|
2022-07-28 11:18:31 +00:00
|
|
|
{
|
|
|
|
Event: user.UserDomainClaimedType,
|
|
|
|
Reduce: p.reduceDomainClaimed,
|
|
|
|
},
|
2021-11-30 07:57:51 +00:00
|
|
|
{
|
|
|
|
Event: user.HumanProfileChangedType,
|
|
|
|
Reduce: p.reduceHumanProfileChanged,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Event: user.UserV1ProfileChangedType,
|
|
|
|
Reduce: p.reduceHumanProfileChanged,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Event: user.HumanPhoneChangedType,
|
|
|
|
Reduce: p.reduceHumanPhoneChanged,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Event: user.UserV1PhoneChangedType,
|
|
|
|
Reduce: p.reduceHumanPhoneChanged,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Event: user.HumanPhoneRemovedType,
|
|
|
|
Reduce: p.reduceHumanPhoneRemoved,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Event: user.UserV1PhoneRemovedType,
|
|
|
|
Reduce: p.reduceHumanPhoneRemoved,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Event: user.HumanPhoneVerifiedType,
|
|
|
|
Reduce: p.reduceHumanPhoneVerified,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Event: user.UserV1PhoneVerifiedType,
|
|
|
|
Reduce: p.reduceHumanPhoneVerified,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Event: user.HumanEmailChangedType,
|
|
|
|
Reduce: p.reduceHumanEmailChanged,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Event: user.UserV1EmailChangedType,
|
|
|
|
Reduce: p.reduceHumanEmailChanged,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Event: user.HumanEmailVerifiedType,
|
|
|
|
Reduce: p.reduceHumanEmailVerified,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Event: user.UserV1EmailVerifiedType,
|
|
|
|
Reduce: p.reduceHumanEmailVerified,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Event: user.HumanAvatarAddedType,
|
|
|
|
Reduce: p.reduceHumanAvatarAdded,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Event: user.HumanAvatarRemovedType,
|
|
|
|
Reduce: p.reduceHumanAvatarRemoved,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Event: user.MachineAddedEventType,
|
|
|
|
Reduce: p.reduceMachineAdded,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Event: user.MachineChangedEventType,
|
|
|
|
Reduce: p.reduceMachineChanged,
|
|
|
|
},
|
2022-07-06 12:09:49 +00:00
|
|
|
{
|
|
|
|
Event: user.HumanPasswordChangedType,
|
|
|
|
Reduce: p.reduceHumanPasswordChanged,
|
|
|
|
},
|
2023-01-31 19:52:47 +00:00
|
|
|
{
|
|
|
|
Event: user.MachineSecretSetType,
|
|
|
|
Reduce: p.reduceMachineSecretSet,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Event: user.MachineSecretRemovedType,
|
|
|
|
Reduce: p.reduceMachineSecretRemoved,
|
|
|
|
},
|
2021-11-30 07:57:51 +00:00
|
|
|
},
|
|
|
|
},
|
2022-11-30 16:01:17 +00:00
|
|
|
{
|
|
|
|
Aggregate: org.AggregateType,
|
2023-10-19 10:19:10 +00:00
|
|
|
EventReducers: []handler.EventReducer{
|
2022-11-30 16:01:17 +00:00
|
|
|
{
|
|
|
|
Event: org.OrgRemovedEventType,
|
|
|
|
Reduce: p.reduceOwnerRemoved,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-10-20 12:36:52 +00:00
|
|
|
{
|
|
|
|
Aggregate: instance.AggregateType,
|
2023-10-19 10:19:10 +00:00
|
|
|
EventReducers: []handler.EventReducer{
|
2022-10-20 12:36:52 +00:00
|
|
|
{
|
|
|
|
Event: instance.InstanceRemovedEventType,
|
|
|
|
Reduce: reduceInstanceRemovedHelper(UserInstanceIDCol),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-11-30 07:57:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-14 05:51:00 +00:00
|
|
|
func (p *userProjection) reduceHumanAdded(event eventstore.Event) (*handler.Statement, error) {
|
2021-11-30 07:57:51 +00:00
|
|
|
e, ok := event.(*user.HumanAddedEvent)
|
|
|
|
if !ok {
|
2023-12-08 14:30:55 +00:00
|
|
|
return nil, zerrors.ThrowInvalidArgumentf(nil, "HANDL-Ebynp", "reduce.wrong.event.type %s", user.HumanAddedType)
|
2021-11-30 07:57:51 +00:00
|
|
|
}
|
2023-10-19 10:19:10 +00:00
|
|
|
return handler.NewMultiStatement(
|
2021-11-30 07:57:51 +00:00
|
|
|
e,
|
2023-10-19 10:19:10 +00:00
|
|
|
handler.AddCreateStatement(
|
2021-11-30 07:57:51 +00:00
|
|
|
[]handler.Column{
|
|
|
|
handler.NewCol(UserIDCol, e.Aggregate().ID),
|
|
|
|
handler.NewCol(UserCreationDateCol, e.CreationDate()),
|
|
|
|
handler.NewCol(UserChangeDateCol, e.CreationDate()),
|
|
|
|
handler.NewCol(UserResourceOwnerCol, e.Aggregate().ResourceOwner),
|
2022-03-23 08:02:39 +00:00
|
|
|
handler.NewCol(UserInstanceIDCol, e.Aggregate().InstanceID),
|
2022-01-25 10:35:38 +00:00
|
|
|
handler.NewCol(UserStateCol, domain.UserStateActive),
|
2021-11-30 07:57:51 +00:00
|
|
|
handler.NewCol(UserSequenceCol, e.Sequence()),
|
|
|
|
handler.NewCol(UserUsernameCol, e.UserName),
|
2022-01-14 09:45:50 +00:00
|
|
|
handler.NewCol(UserTypeCol, domain.UserTypeHuman),
|
2021-11-30 07:57:51 +00:00
|
|
|
},
|
|
|
|
),
|
2023-10-19 10:19:10 +00:00
|
|
|
handler.AddCreateStatement(
|
2021-11-30 07:57:51 +00:00
|
|
|
[]handler.Column{
|
|
|
|
handler.NewCol(HumanUserIDCol, e.Aggregate().ID),
|
2022-05-25 12:15:13 +00:00
|
|
|
handler.NewCol(HumanUserInstanceIDCol, e.Aggregate().InstanceID),
|
2021-12-14 07:19:02 +00:00
|
|
|
handler.NewCol(HumanFirstNameCol, e.FirstName),
|
2021-11-30 07:57:51 +00:00
|
|
|
handler.NewCol(HumanLastNameCol, e.LastName),
|
|
|
|
handler.NewCol(HumanNickNameCol, &sql.NullString{String: e.NickName, Valid: e.NickName != ""}),
|
|
|
|
handler.NewCol(HumanDisplayNameCol, &sql.NullString{String: e.DisplayName, Valid: e.DisplayName != ""}),
|
|
|
|
handler.NewCol(HumanPreferredLanguageCol, &sql.NullString{String: e.PreferredLanguage.String(), Valid: !e.PreferredLanguage.IsRoot()}),
|
|
|
|
handler.NewCol(HumanGenderCol, &sql.NullInt16{Int16: int16(e.Gender), Valid: e.Gender.Specified()}),
|
|
|
|
handler.NewCol(HumanEmailCol, e.EmailAddress),
|
2023-03-14 19:20:38 +00:00
|
|
|
handler.NewCol(HumanPhoneCol, &sql.NullString{String: string(e.PhoneNumber), Valid: e.PhoneNumber != ""}),
|
2021-11-30 07:57:51 +00:00
|
|
|
},
|
2023-10-19 10:19:10 +00:00
|
|
|
handler.WithTableSuffix(UserHumanSuffix),
|
2021-11-30 07:57:51 +00:00
|
|
|
),
|
2023-10-19 10:19:10 +00:00
|
|
|
handler.AddCreateStatement(
|
2022-07-06 12:09:49 +00:00
|
|
|
[]handler.Column{
|
|
|
|
handler.NewCol(NotifyUserIDCol, e.Aggregate().ID),
|
|
|
|
handler.NewCol(NotifyInstanceIDCol, e.Aggregate().InstanceID),
|
|
|
|
handler.NewCol(NotifyLastEmailCol, e.EmailAddress),
|
2023-03-14 19:20:38 +00:00
|
|
|
handler.NewCol(NotifyLastPhoneCol, &sql.NullString{String: string(e.PhoneNumber), Valid: e.PhoneNumber != ""}),
|
2023-09-07 14:06:11 +00:00
|
|
|
handler.NewCol(NotifyPasswordSetCol, user.SecretOrEncodedHash(e.Secret, e.EncodedHash) != ""),
|
2022-07-06 12:09:49 +00:00
|
|
|
},
|
2023-10-19 10:19:10 +00:00
|
|
|
handler.WithTableSuffix(UserNotifySuffix),
|
2022-07-06 12:09:49 +00:00
|
|
|
),
|
2021-11-30 07:57:51 +00:00
|
|
|
), nil
|
|
|
|
}
|
|
|
|
|
2022-06-14 05:51:00 +00:00
|
|
|
func (p *userProjection) reduceHumanRegistered(event eventstore.Event) (*handler.Statement, error) {
|
2021-11-30 07:57:51 +00:00
|
|
|
e, ok := event.(*user.HumanRegisteredEvent)
|
|
|
|
if !ok {
|
2023-12-08 14:30:55 +00:00
|
|
|
return nil, zerrors.ThrowInvalidArgumentf(nil, "HANDL-xE53M", "reduce.wrong.event.type %s", user.HumanRegisteredType)
|
2021-11-30 07:57:51 +00:00
|
|
|
}
|
2023-10-19 10:19:10 +00:00
|
|
|
return handler.NewMultiStatement(
|
2021-11-30 07:57:51 +00:00
|
|
|
e,
|
2023-10-19 10:19:10 +00:00
|
|
|
handler.AddCreateStatement(
|
2021-11-30 07:57:51 +00:00
|
|
|
[]handler.Column{
|
|
|
|
handler.NewCol(UserIDCol, e.Aggregate().ID),
|
|
|
|
handler.NewCol(UserCreationDateCol, e.CreationDate()),
|
|
|
|
handler.NewCol(UserChangeDateCol, e.CreationDate()),
|
|
|
|
handler.NewCol(UserResourceOwnerCol, e.Aggregate().ResourceOwner),
|
2022-03-23 08:02:39 +00:00
|
|
|
handler.NewCol(UserInstanceIDCol, e.Aggregate().InstanceID),
|
2022-01-25 10:35:38 +00:00
|
|
|
handler.NewCol(UserStateCol, domain.UserStateActive),
|
2021-11-30 07:57:51 +00:00
|
|
|
handler.NewCol(UserSequenceCol, e.Sequence()),
|
|
|
|
handler.NewCol(UserUsernameCol, e.UserName),
|
2022-01-14 09:45:50 +00:00
|
|
|
handler.NewCol(UserTypeCol, domain.UserTypeHuman),
|
2021-11-30 07:57:51 +00:00
|
|
|
},
|
|
|
|
),
|
2023-10-19 10:19:10 +00:00
|
|
|
handler.AddCreateStatement(
|
2021-11-30 07:57:51 +00:00
|
|
|
[]handler.Column{
|
|
|
|
handler.NewCol(HumanUserIDCol, e.Aggregate().ID),
|
2022-05-25 12:15:13 +00:00
|
|
|
handler.NewCol(HumanUserInstanceIDCol, e.Aggregate().InstanceID),
|
2021-12-14 07:19:02 +00:00
|
|
|
handler.NewCol(HumanFirstNameCol, e.FirstName),
|
2021-11-30 07:57:51 +00:00
|
|
|
handler.NewCol(HumanLastNameCol, e.LastName),
|
|
|
|
handler.NewCol(HumanNickNameCol, &sql.NullString{String: e.NickName, Valid: e.NickName != ""}),
|
|
|
|
handler.NewCol(HumanDisplayNameCol, &sql.NullString{String: e.DisplayName, Valid: e.DisplayName != ""}),
|
|
|
|
handler.NewCol(HumanPreferredLanguageCol, &sql.NullString{String: e.PreferredLanguage.String(), Valid: !e.PreferredLanguage.IsRoot()}),
|
|
|
|
handler.NewCol(HumanGenderCol, &sql.NullInt16{Int16: int16(e.Gender), Valid: e.Gender.Specified()}),
|
|
|
|
handler.NewCol(HumanEmailCol, e.EmailAddress),
|
2023-03-14 19:20:38 +00:00
|
|
|
handler.NewCol(HumanPhoneCol, &sql.NullString{String: string(e.PhoneNumber), Valid: e.PhoneNumber != ""}),
|
2021-11-30 07:57:51 +00:00
|
|
|
},
|
2023-10-19 10:19:10 +00:00
|
|
|
handler.WithTableSuffix(UserHumanSuffix),
|
2021-11-30 07:57:51 +00:00
|
|
|
),
|
2023-10-19 10:19:10 +00:00
|
|
|
handler.AddCreateStatement(
|
2022-07-06 12:09:49 +00:00
|
|
|
[]handler.Column{
|
|
|
|
handler.NewCol(NotifyUserIDCol, e.Aggregate().ID),
|
|
|
|
handler.NewCol(NotifyInstanceIDCol, e.Aggregate().InstanceID),
|
|
|
|
handler.NewCol(NotifyLastEmailCol, e.EmailAddress),
|
2023-03-14 19:20:38 +00:00
|
|
|
handler.NewCol(NotifyLastPhoneCol, &sql.NullString{String: string(e.PhoneNumber), Valid: e.PhoneNumber != ""}),
|
2023-09-07 14:06:11 +00:00
|
|
|
handler.NewCol(NotifyPasswordSetCol, user.SecretOrEncodedHash(e.Secret, e.EncodedHash) != ""),
|
2022-07-06 12:09:49 +00:00
|
|
|
},
|
2023-10-19 10:19:10 +00:00
|
|
|
handler.WithTableSuffix(UserNotifySuffix),
|
2022-07-06 12:09:49 +00:00
|
|
|
),
|
2021-11-30 07:57:51 +00:00
|
|
|
), nil
|
|
|
|
}
|
|
|
|
|
2022-06-14 05:51:00 +00:00
|
|
|
func (p *userProjection) reduceHumanInitCodeAdded(event eventstore.Event) (*handler.Statement, error) {
|
2022-01-25 10:35:38 +00:00
|
|
|
e, ok := event.(*user.HumanInitialCodeAddedEvent)
|
|
|
|
if !ok {
|
2023-12-08 14:30:55 +00:00
|
|
|
return nil, zerrors.ThrowInvalidArgumentf(nil, "HANDL-Dvgws", "reduce.wrong.event.type %s", user.HumanInitialCodeAddedType)
|
2022-01-25 10:35:38 +00:00
|
|
|
}
|
2023-10-19 10:19:10 +00:00
|
|
|
return handler.NewUpdateStatement(
|
2022-01-25 10:35:38 +00:00
|
|
|
e,
|
|
|
|
[]handler.Column{
|
|
|
|
handler.NewCol(UserStateCol, domain.UserStateInitial),
|
|
|
|
},
|
|
|
|
[]handler.Condition{
|
|
|
|
handler.NewCond(UserIDCol, e.Aggregate().ID),
|
2022-05-25 12:15:13 +00:00
|
|
|
handler.NewCond(HumanUserInstanceIDCol, e.Aggregate().InstanceID),
|
2022-01-25 10:35:38 +00:00
|
|
|
},
|
|
|
|
), nil
|
|
|
|
}
|
|
|
|
|
2022-06-14 05:51:00 +00:00
|
|
|
func (p *userProjection) reduceHumanInitCodeSucceeded(event eventstore.Event) (*handler.Statement, error) {
|
2022-01-25 10:35:38 +00:00
|
|
|
e, ok := event.(*user.HumanInitializedCheckSucceededEvent)
|
|
|
|
if !ok {
|
2023-12-08 14:30:55 +00:00
|
|
|
return nil, zerrors.ThrowInvalidArgumentf(nil, "HANDL-Dfvwq", "reduce.wrong.event.type %s", user.HumanInitializedCheckSucceededType)
|
2022-01-25 10:35:38 +00:00
|
|
|
}
|
2023-10-19 10:19:10 +00:00
|
|
|
return handler.NewUpdateStatement(
|
2022-01-25 10:35:38 +00:00
|
|
|
e,
|
|
|
|
[]handler.Column{
|
|
|
|
handler.NewCol(UserStateCol, domain.UserStateActive),
|
|
|
|
},
|
|
|
|
[]handler.Condition{
|
|
|
|
handler.NewCond(UserIDCol, e.Aggregate().ID),
|
2022-05-25 12:15:13 +00:00
|
|
|
handler.NewCond(HumanUserInstanceIDCol, e.Aggregate().InstanceID),
|
2022-01-25 10:35:38 +00:00
|
|
|
},
|
|
|
|
), nil
|
|
|
|
}
|
|
|
|
|
2022-06-14 05:51:00 +00:00
|
|
|
func (p *userProjection) reduceUserLocked(event eventstore.Event) (*handler.Statement, error) {
|
2021-11-30 07:57:51 +00:00
|
|
|
e, ok := event.(*user.UserLockedEvent)
|
|
|
|
if !ok {
|
2023-12-08 14:30:55 +00:00
|
|
|
return nil, zerrors.ThrowInvalidArgumentf(nil, "HANDL-exyBF", "reduce.wrong.event.type %s", user.UserLockedType)
|
2021-11-30 07:57:51 +00:00
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
return handler.NewUpdateStatement(
|
2021-11-30 07:57:51 +00:00
|
|
|
e,
|
|
|
|
[]handler.Column{
|
|
|
|
handler.NewCol(UserChangeDateCol, e.CreationDate()),
|
|
|
|
handler.NewCol(UserStateCol, domain.UserStateLocked),
|
|
|
|
handler.NewCol(UserSequenceCol, e.Sequence()),
|
|
|
|
},
|
|
|
|
[]handler.Condition{
|
|
|
|
handler.NewCond(UserIDCol, e.Aggregate().ID),
|
2022-05-25 12:15:13 +00:00
|
|
|
handler.NewCond(UserInstanceIDCol, e.Aggregate().InstanceID),
|
2021-11-30 07:57:51 +00:00
|
|
|
},
|
|
|
|
), nil
|
|
|
|
}
|
|
|
|
|
2022-06-14 05:51:00 +00:00
|
|
|
func (p *userProjection) reduceUserUnlocked(event eventstore.Event) (*handler.Statement, error) {
|
2021-11-30 07:57:51 +00:00
|
|
|
e, ok := event.(*user.UserUnlockedEvent)
|
|
|
|
if !ok {
|
2023-12-08 14:30:55 +00:00
|
|
|
return nil, zerrors.ThrowInvalidArgumentf(nil, "HANDL-JIyRl", "reduce.wrong.event.type %s", user.UserUnlockedType)
|
2021-11-30 07:57:51 +00:00
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
return handler.NewUpdateStatement(
|
2021-11-30 07:57:51 +00:00
|
|
|
e,
|
|
|
|
[]handler.Column{
|
|
|
|
handler.NewCol(UserChangeDateCol, e.CreationDate()),
|
|
|
|
handler.NewCol(UserStateCol, domain.UserStateActive),
|
|
|
|
handler.NewCol(UserSequenceCol, e.Sequence()),
|
|
|
|
},
|
|
|
|
[]handler.Condition{
|
|
|
|
handler.NewCond(UserIDCol, e.Aggregate().ID),
|
2022-05-25 12:15:13 +00:00
|
|
|
handler.NewCond(UserInstanceIDCol, e.Aggregate().InstanceID),
|
2021-11-30 07:57:51 +00:00
|
|
|
},
|
|
|
|
), nil
|
|
|
|
}
|
|
|
|
|
2022-06-14 05:51:00 +00:00
|
|
|
func (p *userProjection) reduceUserDeactivated(event eventstore.Event) (*handler.Statement, error) {
|
2021-11-30 07:57:51 +00:00
|
|
|
e, ok := event.(*user.UserDeactivatedEvent)
|
|
|
|
if !ok {
|
2023-12-08 14:30:55 +00:00
|
|
|
return nil, zerrors.ThrowInvalidArgumentf(nil, "HANDL-6BNjj", "reduce.wrong.event.type %s", user.UserDeactivatedType)
|
2021-11-30 07:57:51 +00:00
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
return handler.NewUpdateStatement(
|
2021-11-30 07:57:51 +00:00
|
|
|
e,
|
|
|
|
[]handler.Column{
|
|
|
|
handler.NewCol(UserChangeDateCol, e.CreationDate()),
|
|
|
|
handler.NewCol(UserStateCol, domain.UserStateInactive),
|
|
|
|
handler.NewCol(UserSequenceCol, e.Sequence()),
|
|
|
|
},
|
|
|
|
[]handler.Condition{
|
|
|
|
handler.NewCond(UserIDCol, e.Aggregate().ID),
|
2022-05-25 12:15:13 +00:00
|
|
|
handler.NewCond(UserInstanceIDCol, e.Aggregate().InstanceID),
|
2021-11-30 07:57:51 +00:00
|
|
|
},
|
|
|
|
), nil
|
|
|
|
}
|
|
|
|
|
2022-06-14 05:51:00 +00:00
|
|
|
func (p *userProjection) reduceUserReactivated(event eventstore.Event) (*handler.Statement, error) {
|
2021-11-30 07:57:51 +00:00
|
|
|
e, ok := event.(*user.UserReactivatedEvent)
|
|
|
|
if !ok {
|
2023-12-08 14:30:55 +00:00
|
|
|
return nil, zerrors.ThrowInvalidArgumentf(nil, "HANDL-IoF6j", "reduce.wrong.event.type %s", user.UserReactivatedType)
|
2021-11-30 07:57:51 +00:00
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
return handler.NewUpdateStatement(
|
2021-11-30 07:57:51 +00:00
|
|
|
e,
|
|
|
|
[]handler.Column{
|
|
|
|
handler.NewCol(UserChangeDateCol, e.CreationDate()),
|
|
|
|
handler.NewCol(UserStateCol, domain.UserStateActive),
|
|
|
|
handler.NewCol(UserSequenceCol, e.Sequence()),
|
|
|
|
},
|
|
|
|
[]handler.Condition{
|
|
|
|
handler.NewCond(UserIDCol, e.Aggregate().ID),
|
2022-05-25 12:15:13 +00:00
|
|
|
handler.NewCond(UserInstanceIDCol, e.Aggregate().InstanceID),
|
2021-11-30 07:57:51 +00:00
|
|
|
},
|
|
|
|
), nil
|
|
|
|
}
|
|
|
|
|
2022-06-14 05:51:00 +00:00
|
|
|
func (p *userProjection) reduceUserRemoved(event eventstore.Event) (*handler.Statement, error) {
|
2021-11-30 07:57:51 +00:00
|
|
|
e, ok := event.(*user.UserRemovedEvent)
|
|
|
|
if !ok {
|
2023-12-08 14:30:55 +00:00
|
|
|
return nil, zerrors.ThrowInvalidArgumentf(nil, "HANDL-BQB2t", "reduce.wrong.event.type %s", user.UserRemovedType)
|
2021-11-30 07:57:51 +00:00
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
return handler.NewDeleteStatement(
|
2021-11-30 07:57:51 +00:00
|
|
|
e,
|
|
|
|
[]handler.Condition{
|
|
|
|
handler.NewCond(UserIDCol, e.Aggregate().ID),
|
2022-05-25 12:15:13 +00:00
|
|
|
handler.NewCond(UserInstanceIDCol, e.Aggregate().InstanceID),
|
2021-11-30 07:57:51 +00:00
|
|
|
},
|
|
|
|
), nil
|
|
|
|
}
|
|
|
|
|
2022-06-14 05:51:00 +00:00
|
|
|
func (p *userProjection) reduceUserNameChanged(event eventstore.Event) (*handler.Statement, error) {
|
2021-11-30 07:57:51 +00:00
|
|
|
e, ok := event.(*user.UsernameChangedEvent)
|
|
|
|
if !ok {
|
2023-12-08 14:30:55 +00:00
|
|
|
return nil, zerrors.ThrowInvalidArgumentf(nil, "HANDL-QNKyV", "reduce.wrong.event.type %s", user.UserUserNameChangedType)
|
2021-11-30 07:57:51 +00:00
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
return handler.NewUpdateStatement(
|
2021-11-30 07:57:51 +00:00
|
|
|
e,
|
|
|
|
[]handler.Column{
|
|
|
|
handler.NewCol(UserChangeDateCol, e.CreationDate()),
|
|
|
|
handler.NewCol(UserUsernameCol, e.UserName),
|
|
|
|
handler.NewCol(UserSequenceCol, e.Sequence()),
|
|
|
|
},
|
|
|
|
[]handler.Condition{
|
|
|
|
handler.NewCond(UserIDCol, e.Aggregate().ID),
|
2022-05-25 12:15:13 +00:00
|
|
|
handler.NewCond(UserInstanceIDCol, e.Aggregate().InstanceID),
|
2021-11-30 07:57:51 +00:00
|
|
|
},
|
|
|
|
), nil
|
|
|
|
}
|
|
|
|
|
2022-07-28 11:18:31 +00:00
|
|
|
func (p *userProjection) reduceDomainClaimed(event eventstore.Event) (*handler.Statement, error) {
|
|
|
|
e, ok := event.(*user.DomainClaimedEvent)
|
|
|
|
if !ok {
|
2023-12-08 14:30:55 +00:00
|
|
|
return nil, zerrors.ThrowInvalidArgumentf(nil, "HANDL-ASwf3", "reduce.wrong.event.type %s", user.UserDomainClaimedType)
|
2022-07-28 11:18:31 +00:00
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
return handler.NewUpdateStatement(
|
2022-07-28 11:18:31 +00:00
|
|
|
e,
|
|
|
|
[]handler.Column{
|
|
|
|
handler.NewCol(UserChangeDateCol, e.CreationDate()),
|
|
|
|
handler.NewCol(UserUsernameCol, e.UserName),
|
|
|
|
handler.NewCol(UserSequenceCol, e.Sequence()),
|
|
|
|
},
|
|
|
|
[]handler.Condition{
|
|
|
|
handler.NewCond(UserIDCol, e.Aggregate().ID),
|
|
|
|
handler.NewCond(UserInstanceIDCol, e.Aggregate().InstanceID),
|
|
|
|
},
|
|
|
|
), nil
|
|
|
|
}
|
|
|
|
|
2022-06-14 05:51:00 +00:00
|
|
|
func (p *userProjection) reduceHumanProfileChanged(event eventstore.Event) (*handler.Statement, error) {
|
2021-11-30 07:57:51 +00:00
|
|
|
e, ok := event.(*user.HumanProfileChangedEvent)
|
|
|
|
if !ok {
|
2023-12-08 14:30:55 +00:00
|
|
|
return nil, zerrors.ThrowInvalidArgumentf(nil, "HANDL-769v4", "reduce.wrong.event.type %s", user.HumanProfileChangedType)
|
2021-11-30 07:57:51 +00:00
|
|
|
}
|
|
|
|
cols := make([]handler.Column, 0, 6)
|
2021-12-06 16:22:59 +00:00
|
|
|
if e.FirstName != "" {
|
2021-12-14 07:19:02 +00:00
|
|
|
cols = append(cols, handler.NewCol(HumanFirstNameCol, e.FirstName))
|
2021-12-06 16:22:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if e.LastName != "" {
|
|
|
|
cols = append(cols, handler.NewCol(HumanLastNameCol, e.LastName))
|
|
|
|
}
|
2021-11-30 07:57:51 +00:00
|
|
|
|
|
|
|
if e.NickName != nil {
|
|
|
|
cols = append(cols, handler.NewCol(HumanNickNameCol, *e.NickName))
|
|
|
|
}
|
|
|
|
|
|
|
|
if e.DisplayName != nil {
|
|
|
|
cols = append(cols, handler.NewCol(HumanDisplayNameCol, *e.DisplayName))
|
|
|
|
}
|
|
|
|
|
|
|
|
if e.PreferredLanguage != nil {
|
|
|
|
cols = append(cols, handler.NewCol(HumanPreferredLanguageCol, e.PreferredLanguage.String()))
|
|
|
|
}
|
|
|
|
|
|
|
|
if e.Gender != nil {
|
|
|
|
cols = append(cols, handler.NewCol(HumanGenderCol, *e.Gender))
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
return handler.NewMultiStatement(
|
2021-11-30 07:57:51 +00:00
|
|
|
e,
|
2023-10-19 10:19:10 +00:00
|
|
|
handler.AddUpdateStatement(
|
2021-11-30 07:57:51 +00:00
|
|
|
[]handler.Column{
|
|
|
|
handler.NewCol(UserChangeDateCol, e.CreationDate()),
|
|
|
|
handler.NewCol(UserSequenceCol, e.Sequence()),
|
|
|
|
},
|
|
|
|
[]handler.Condition{
|
|
|
|
handler.NewCond(UserIDCol, e.Aggregate().ID),
|
2022-05-25 12:15:13 +00:00
|
|
|
handler.NewCond(UserInstanceIDCol, e.Aggregate().InstanceID),
|
2021-11-30 07:57:51 +00:00
|
|
|
},
|
|
|
|
),
|
2023-10-19 10:19:10 +00:00
|
|
|
handler.AddUpdateStatement(
|
2021-11-30 07:57:51 +00:00
|
|
|
cols,
|
|
|
|
[]handler.Condition{
|
|
|
|
handler.NewCond(HumanUserIDCol, e.Aggregate().ID),
|
2022-05-25 12:15:13 +00:00
|
|
|
handler.NewCond(HumanUserInstanceIDCol, e.Aggregate().InstanceID),
|
2021-11-30 07:57:51 +00:00
|
|
|
},
|
2023-10-19 10:19:10 +00:00
|
|
|
handler.WithTableSuffix(UserHumanSuffix),
|
2021-11-30 07:57:51 +00:00
|
|
|
),
|
|
|
|
), nil
|
|
|
|
}
|
|
|
|
|
2022-06-14 05:51:00 +00:00
|
|
|
func (p *userProjection) reduceHumanPhoneChanged(event eventstore.Event) (*handler.Statement, error) {
|
2021-11-30 07:57:51 +00:00
|
|
|
e, ok := event.(*user.HumanPhoneChangedEvent)
|
|
|
|
if !ok {
|
2023-12-08 14:30:55 +00:00
|
|
|
return nil, zerrors.ThrowInvalidArgumentf(nil, "HANDL-xOGIA", "reduce.wrong.event.type %s", user.HumanPhoneChangedType)
|
2021-11-30 07:57:51 +00:00
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
return handler.NewMultiStatement(
|
2021-11-30 07:57:51 +00:00
|
|
|
e,
|
2023-10-19 10:19:10 +00:00
|
|
|
handler.AddUpdateStatement(
|
2021-11-30 07:57:51 +00:00
|
|
|
[]handler.Column{
|
|
|
|
handler.NewCol(UserChangeDateCol, e.CreationDate()),
|
|
|
|
handler.NewCol(UserSequenceCol, e.Sequence()),
|
|
|
|
},
|
|
|
|
[]handler.Condition{
|
|
|
|
handler.NewCond(UserIDCol, e.Aggregate().ID),
|
2022-05-25 12:15:13 +00:00
|
|
|
handler.NewCond(UserInstanceIDCol, e.Aggregate().InstanceID),
|
2021-11-30 07:57:51 +00:00
|
|
|
},
|
|
|
|
),
|
2023-10-19 10:19:10 +00:00
|
|
|
handler.AddUpdateStatement(
|
2021-11-30 07:57:51 +00:00
|
|
|
[]handler.Column{
|
|
|
|
handler.NewCol(HumanPhoneCol, e.PhoneNumber),
|
|
|
|
handler.NewCol(HumanIsPhoneVerifiedCol, false),
|
|
|
|
},
|
|
|
|
[]handler.Condition{
|
|
|
|
handler.NewCond(HumanUserIDCol, e.Aggregate().ID),
|
2022-05-25 12:15:13 +00:00
|
|
|
handler.NewCond(HumanUserInstanceIDCol, e.Aggregate().InstanceID),
|
2021-11-30 07:57:51 +00:00
|
|
|
},
|
2023-10-19 10:19:10 +00:00
|
|
|
handler.WithTableSuffix(UserHumanSuffix),
|
2021-11-30 07:57:51 +00:00
|
|
|
),
|
2023-10-19 10:19:10 +00:00
|
|
|
handler.AddUpdateStatement(
|
2022-07-06 12:09:49 +00:00
|
|
|
[]handler.Column{
|
2023-03-14 19:20:38 +00:00
|
|
|
handler.NewCol(NotifyLastPhoneCol, &sql.NullString{String: string(e.PhoneNumber), Valid: e.PhoneNumber != ""}),
|
2022-07-06 12:09:49 +00:00
|
|
|
},
|
|
|
|
[]handler.Condition{
|
|
|
|
handler.NewCond(NotifyUserIDCol, e.Aggregate().ID),
|
|
|
|
handler.NewCond(NotifyInstanceIDCol, e.Aggregate().InstanceID),
|
|
|
|
},
|
2023-10-19 10:19:10 +00:00
|
|
|
handler.WithTableSuffix(UserNotifySuffix),
|
2022-07-06 12:09:49 +00:00
|
|
|
),
|
2021-11-30 07:57:51 +00:00
|
|
|
), nil
|
|
|
|
}
|
|
|
|
|
2022-06-14 05:51:00 +00:00
|
|
|
func (p *userProjection) reduceHumanPhoneRemoved(event eventstore.Event) (*handler.Statement, error) {
|
2021-11-30 07:57:51 +00:00
|
|
|
e, ok := event.(*user.HumanPhoneRemovedEvent)
|
|
|
|
if !ok {
|
2023-12-08 14:30:55 +00:00
|
|
|
return nil, zerrors.ThrowInvalidArgumentf(nil, "HANDL-JI4S1", "reduce.wrong.event.type %s", user.HumanPhoneRemovedType)
|
2021-11-30 07:57:51 +00:00
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
return handler.NewMultiStatement(
|
2021-11-30 07:57:51 +00:00
|
|
|
e,
|
2023-10-19 10:19:10 +00:00
|
|
|
handler.AddUpdateStatement(
|
2021-11-30 07:57:51 +00:00
|
|
|
[]handler.Column{
|
|
|
|
handler.NewCol(UserChangeDateCol, e.CreationDate()),
|
|
|
|
handler.NewCol(UserSequenceCol, e.Sequence()),
|
|
|
|
},
|
|
|
|
[]handler.Condition{
|
|
|
|
handler.NewCond(UserIDCol, e.Aggregate().ID),
|
2022-05-25 12:15:13 +00:00
|
|
|
handler.NewCond(UserInstanceIDCol, e.Aggregate().InstanceID),
|
2021-11-30 07:57:51 +00:00
|
|
|
},
|
|
|
|
),
|
2023-10-19 10:19:10 +00:00
|
|
|
handler.AddUpdateStatement(
|
2021-11-30 07:57:51 +00:00
|
|
|
[]handler.Column{
|
|
|
|
handler.NewCol(HumanPhoneCol, nil),
|
|
|
|
handler.NewCol(HumanIsPhoneVerifiedCol, nil),
|
|
|
|
},
|
|
|
|
[]handler.Condition{
|
|
|
|
handler.NewCond(HumanUserIDCol, e.Aggregate().ID),
|
2022-05-25 12:15:13 +00:00
|
|
|
handler.NewCond(HumanUserInstanceIDCol, e.Aggregate().InstanceID),
|
2021-11-30 07:57:51 +00:00
|
|
|
},
|
2023-10-19 10:19:10 +00:00
|
|
|
handler.WithTableSuffix(UserHumanSuffix),
|
2021-11-30 07:57:51 +00:00
|
|
|
),
|
2023-10-19 10:19:10 +00:00
|
|
|
handler.AddUpdateStatement(
|
2022-07-06 12:09:49 +00:00
|
|
|
[]handler.Column{
|
|
|
|
handler.NewCol(NotifyLastPhoneCol, nil),
|
|
|
|
handler.NewCol(NotifyVerifiedPhoneCol, nil),
|
|
|
|
},
|
|
|
|
[]handler.Condition{
|
|
|
|
handler.NewCond(NotifyUserIDCol, e.Aggregate().ID),
|
|
|
|
handler.NewCond(NotifyInstanceIDCol, e.Aggregate().InstanceID),
|
|
|
|
},
|
2023-10-19 10:19:10 +00:00
|
|
|
handler.WithTableSuffix(UserNotifySuffix),
|
2022-07-06 12:09:49 +00:00
|
|
|
),
|
2021-11-30 07:57:51 +00:00
|
|
|
), nil
|
|
|
|
}
|
|
|
|
|
2022-06-14 05:51:00 +00:00
|
|
|
func (p *userProjection) reduceHumanPhoneVerified(event eventstore.Event) (*handler.Statement, error) {
|
2021-11-30 07:57:51 +00:00
|
|
|
e, ok := event.(*user.HumanPhoneVerifiedEvent)
|
|
|
|
if !ok {
|
2023-12-08 14:30:55 +00:00
|
|
|
return nil, zerrors.ThrowInvalidArgumentf(nil, "HANDL-LBnqG", "reduce.wrong.event.type %s", user.HumanPhoneVerifiedType)
|
2021-11-30 07:57:51 +00:00
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
return handler.NewMultiStatement(
|
2021-11-30 07:57:51 +00:00
|
|
|
e,
|
2023-10-19 10:19:10 +00:00
|
|
|
handler.AddUpdateStatement(
|
2021-11-30 07:57:51 +00:00
|
|
|
[]handler.Column{
|
|
|
|
handler.NewCol(UserChangeDateCol, e.CreationDate()),
|
|
|
|
handler.NewCol(UserSequenceCol, e.Sequence()),
|
|
|
|
},
|
|
|
|
[]handler.Condition{
|
|
|
|
handler.NewCond(UserIDCol, e.Aggregate().ID),
|
2022-05-25 12:15:13 +00:00
|
|
|
handler.NewCond(UserInstanceIDCol, e.Aggregate().InstanceID),
|
2021-11-30 07:57:51 +00:00
|
|
|
},
|
|
|
|
),
|
2023-10-19 10:19:10 +00:00
|
|
|
handler.AddUpdateStatement(
|
2021-11-30 07:57:51 +00:00
|
|
|
[]handler.Column{
|
|
|
|
handler.NewCol(HumanIsPhoneVerifiedCol, true),
|
|
|
|
},
|
|
|
|
[]handler.Condition{
|
|
|
|
handler.NewCond(HumanUserIDCol, e.Aggregate().ID),
|
2022-05-25 12:15:13 +00:00
|
|
|
handler.NewCond(HumanUserInstanceIDCol, e.Aggregate().InstanceID),
|
2021-11-30 07:57:51 +00:00
|
|
|
},
|
2023-10-19 10:19:10 +00:00
|
|
|
handler.WithTableSuffix(UserHumanSuffix),
|
2021-11-30 07:57:51 +00:00
|
|
|
),
|
2023-10-19 10:19:10 +00:00
|
|
|
handler.AddUpdateStatement(
|
2022-07-06 12:09:49 +00:00
|
|
|
[]handler.Column{
|
2023-10-19 10:19:10 +00:00
|
|
|
handler.NewCopyCol(NotifyVerifiedPhoneCol, NotifyLastPhoneCol),
|
2022-07-06 12:09:49 +00:00
|
|
|
},
|
|
|
|
[]handler.Condition{
|
|
|
|
handler.NewCond(NotifyUserIDCol, e.Aggregate().ID),
|
|
|
|
handler.NewCond(NotifyInstanceIDCol, e.Aggregate().InstanceID),
|
|
|
|
},
|
2023-10-19 10:19:10 +00:00
|
|
|
handler.WithTableSuffix(UserNotifySuffix),
|
2022-07-06 12:09:49 +00:00
|
|
|
),
|
2021-11-30 07:57:51 +00:00
|
|
|
), nil
|
|
|
|
}
|
|
|
|
|
2022-06-14 05:51:00 +00:00
|
|
|
func (p *userProjection) reduceHumanEmailChanged(event eventstore.Event) (*handler.Statement, error) {
|
2021-11-30 07:57:51 +00:00
|
|
|
e, ok := event.(*user.HumanEmailChangedEvent)
|
|
|
|
if !ok {
|
2023-12-08 14:30:55 +00:00
|
|
|
return nil, zerrors.ThrowInvalidArgumentf(nil, "HANDL-KwiHa", "reduce.wrong.event.type %s", user.HumanEmailChangedType)
|
2021-11-30 07:57:51 +00:00
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
return handler.NewMultiStatement(
|
2021-11-30 07:57:51 +00:00
|
|
|
e,
|
2023-10-19 10:19:10 +00:00
|
|
|
handler.AddUpdateStatement(
|
2021-11-30 07:57:51 +00:00
|
|
|
[]handler.Column{
|
|
|
|
handler.NewCol(UserChangeDateCol, e.CreationDate()),
|
|
|
|
handler.NewCol(UserSequenceCol, e.Sequence()),
|
|
|
|
},
|
|
|
|
[]handler.Condition{
|
|
|
|
handler.NewCond(UserIDCol, e.Aggregate().ID),
|
2022-05-25 12:15:13 +00:00
|
|
|
handler.NewCond(UserInstanceIDCol, e.Aggregate().InstanceID),
|
2021-11-30 07:57:51 +00:00
|
|
|
},
|
|
|
|
),
|
2023-10-19 10:19:10 +00:00
|
|
|
handler.AddUpdateStatement(
|
2021-11-30 07:57:51 +00:00
|
|
|
[]handler.Column{
|
|
|
|
handler.NewCol(HumanEmailCol, e.EmailAddress),
|
|
|
|
handler.NewCol(HumanIsEmailVerifiedCol, false),
|
|
|
|
},
|
|
|
|
[]handler.Condition{
|
|
|
|
handler.NewCond(HumanUserIDCol, e.Aggregate().ID),
|
2022-05-25 12:15:13 +00:00
|
|
|
handler.NewCond(HumanUserInstanceIDCol, e.Aggregate().InstanceID),
|
2021-11-30 07:57:51 +00:00
|
|
|
},
|
2023-10-19 10:19:10 +00:00
|
|
|
handler.WithTableSuffix(UserHumanSuffix),
|
2021-11-30 07:57:51 +00:00
|
|
|
),
|
2023-10-19 10:19:10 +00:00
|
|
|
handler.AddUpdateStatement(
|
2022-07-06 12:09:49 +00:00
|
|
|
[]handler.Column{
|
2023-03-14 19:20:38 +00:00
|
|
|
handler.NewCol(NotifyLastEmailCol, &sql.NullString{String: string(e.EmailAddress), Valid: e.EmailAddress != ""}),
|
2022-07-06 12:09:49 +00:00
|
|
|
},
|
|
|
|
[]handler.Condition{
|
|
|
|
handler.NewCond(NotifyUserIDCol, e.Aggregate().ID),
|
|
|
|
handler.NewCond(NotifyInstanceIDCol, e.Aggregate().InstanceID),
|
|
|
|
},
|
2023-10-19 10:19:10 +00:00
|
|
|
handler.WithTableSuffix(UserNotifySuffix),
|
2022-07-06 12:09:49 +00:00
|
|
|
),
|
2021-11-30 07:57:51 +00:00
|
|
|
), nil
|
|
|
|
}
|
|
|
|
|
2022-06-14 05:51:00 +00:00
|
|
|
func (p *userProjection) reduceHumanEmailVerified(event eventstore.Event) (*handler.Statement, error) {
|
2021-11-30 07:57:51 +00:00
|
|
|
e, ok := event.(*user.HumanEmailVerifiedEvent)
|
|
|
|
if !ok {
|
2023-12-08 14:30:55 +00:00
|
|
|
return nil, zerrors.ThrowInvalidArgumentf(nil, "HANDL-JzcDq", "reduce.wrong.event.type %s", user.HumanEmailVerifiedType)
|
2021-11-30 07:57:51 +00:00
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
return handler.NewMultiStatement(
|
2021-11-30 07:57:51 +00:00
|
|
|
e,
|
2023-10-19 10:19:10 +00:00
|
|
|
handler.AddUpdateStatement(
|
2021-11-30 07:57:51 +00:00
|
|
|
[]handler.Column{
|
|
|
|
handler.NewCol(UserChangeDateCol, e.CreationDate()),
|
|
|
|
handler.NewCol(UserSequenceCol, e.Sequence()),
|
|
|
|
},
|
|
|
|
[]handler.Condition{
|
|
|
|
handler.NewCond(UserIDCol, e.Aggregate().ID),
|
2022-05-25 12:15:13 +00:00
|
|
|
handler.NewCond(UserInstanceIDCol, e.Aggregate().InstanceID),
|
2021-11-30 07:57:51 +00:00
|
|
|
},
|
|
|
|
),
|
2023-10-19 10:19:10 +00:00
|
|
|
handler.AddUpdateStatement(
|
2021-11-30 07:57:51 +00:00
|
|
|
[]handler.Column{
|
|
|
|
handler.NewCol(HumanIsEmailVerifiedCol, true),
|
|
|
|
},
|
|
|
|
[]handler.Condition{
|
|
|
|
handler.NewCond(HumanUserIDCol, e.Aggregate().ID),
|
2022-05-25 12:15:13 +00:00
|
|
|
handler.NewCond(HumanUserInstanceIDCol, e.Aggregate().InstanceID),
|
2021-11-30 07:57:51 +00:00
|
|
|
},
|
2023-10-19 10:19:10 +00:00
|
|
|
handler.WithTableSuffix(UserHumanSuffix),
|
2021-11-30 07:57:51 +00:00
|
|
|
),
|
2023-10-19 10:19:10 +00:00
|
|
|
handler.AddUpdateStatement(
|
2022-07-06 12:09:49 +00:00
|
|
|
[]handler.Column{
|
2023-10-19 10:19:10 +00:00
|
|
|
handler.NewCopyCol(NotifyVerifiedEmailCol, NotifyLastEmailCol),
|
2022-07-06 12:09:49 +00:00
|
|
|
},
|
|
|
|
[]handler.Condition{
|
|
|
|
handler.NewCond(NotifyUserIDCol, e.Aggregate().ID),
|
|
|
|
handler.NewCond(NotifyInstanceIDCol, e.Aggregate().InstanceID),
|
|
|
|
},
|
2023-10-19 10:19:10 +00:00
|
|
|
handler.WithTableSuffix(UserNotifySuffix),
|
2022-07-06 12:09:49 +00:00
|
|
|
),
|
2021-11-30 07:57:51 +00:00
|
|
|
), nil
|
|
|
|
}
|
|
|
|
|
2022-06-14 05:51:00 +00:00
|
|
|
func (p *userProjection) reduceHumanAvatarAdded(event eventstore.Event) (*handler.Statement, error) {
|
2021-11-30 07:57:51 +00:00
|
|
|
e, ok := event.(*user.HumanAvatarAddedEvent)
|
|
|
|
if !ok {
|
2023-12-08 14:30:55 +00:00
|
|
|
return nil, zerrors.ThrowInvalidArgumentf(nil, "HANDL-eDEdt", "reduce.wrong.event.type %s", user.HumanAvatarAddedType)
|
2021-11-30 07:57:51 +00:00
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
return handler.NewMultiStatement(
|
2021-11-30 07:57:51 +00:00
|
|
|
e,
|
2023-10-19 10:19:10 +00:00
|
|
|
handler.AddUpdateStatement(
|
2021-11-30 07:57:51 +00:00
|
|
|
[]handler.Column{
|
|
|
|
handler.NewCol(UserChangeDateCol, e.CreationDate()),
|
|
|
|
handler.NewCol(UserSequenceCol, e.Sequence()),
|
|
|
|
},
|
|
|
|
[]handler.Condition{
|
|
|
|
handler.NewCond(UserIDCol, e.Aggregate().ID),
|
2022-05-25 12:15:13 +00:00
|
|
|
handler.NewCond(UserInstanceIDCol, e.Aggregate().InstanceID),
|
2021-11-30 07:57:51 +00:00
|
|
|
},
|
|
|
|
),
|
2023-10-19 10:19:10 +00:00
|
|
|
handler.AddUpdateStatement(
|
2021-11-30 07:57:51 +00:00
|
|
|
[]handler.Column{
|
2022-01-20 14:40:25 +00:00
|
|
|
handler.NewCol(HumanAvatarURLCol, e.StoreKey),
|
2021-11-30 07:57:51 +00:00
|
|
|
},
|
|
|
|
[]handler.Condition{
|
|
|
|
handler.NewCond(HumanUserIDCol, e.Aggregate().ID),
|
2022-05-25 12:15:13 +00:00
|
|
|
handler.NewCond(HumanUserInstanceIDCol, e.Aggregate().InstanceID),
|
2021-11-30 07:57:51 +00:00
|
|
|
},
|
2023-10-19 10:19:10 +00:00
|
|
|
handler.WithTableSuffix(UserHumanSuffix),
|
2021-11-30 07:57:51 +00:00
|
|
|
),
|
|
|
|
), nil
|
|
|
|
}
|
|
|
|
|
2022-06-14 05:51:00 +00:00
|
|
|
func (p *userProjection) reduceHumanAvatarRemoved(event eventstore.Event) (*handler.Statement, error) {
|
2021-11-30 07:57:51 +00:00
|
|
|
e, ok := event.(*user.HumanAvatarRemovedEvent)
|
|
|
|
if !ok {
|
2023-12-08 14:30:55 +00:00
|
|
|
return nil, zerrors.ThrowInvalidArgumentf(nil, "HANDL-KhETX", "reduce.wrong.event.type %s", user.HumanAvatarRemovedType)
|
2021-11-30 07:57:51 +00:00
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
return handler.NewMultiStatement(
|
2021-11-30 07:57:51 +00:00
|
|
|
e,
|
2023-10-19 10:19:10 +00:00
|
|
|
handler.AddUpdateStatement(
|
2021-11-30 07:57:51 +00:00
|
|
|
[]handler.Column{
|
|
|
|
handler.NewCol(UserChangeDateCol, e.CreationDate()),
|
|
|
|
handler.NewCol(UserSequenceCol, e.Sequence()),
|
|
|
|
},
|
|
|
|
[]handler.Condition{
|
|
|
|
handler.NewCond(UserIDCol, e.Aggregate().ID),
|
2022-05-25 12:15:13 +00:00
|
|
|
handler.NewCond(UserInstanceIDCol, e.Aggregate().InstanceID),
|
2021-11-30 07:57:51 +00:00
|
|
|
},
|
|
|
|
),
|
2023-10-19 10:19:10 +00:00
|
|
|
handler.AddUpdateStatement(
|
2021-11-30 07:57:51 +00:00
|
|
|
[]handler.Column{
|
2022-01-20 14:40:25 +00:00
|
|
|
handler.NewCol(HumanAvatarURLCol, nil),
|
2021-11-30 07:57:51 +00:00
|
|
|
},
|
|
|
|
[]handler.Condition{
|
|
|
|
handler.NewCond(HumanUserIDCol, e.Aggregate().ID),
|
2022-05-25 12:15:13 +00:00
|
|
|
handler.NewCond(HumanUserInstanceIDCol, e.Aggregate().InstanceID),
|
2021-11-30 07:57:51 +00:00
|
|
|
},
|
2023-10-19 10:19:10 +00:00
|
|
|
handler.WithTableSuffix(UserHumanSuffix),
|
2021-11-30 07:57:51 +00:00
|
|
|
),
|
|
|
|
), nil
|
|
|
|
}
|
|
|
|
|
2022-07-06 12:09:49 +00:00
|
|
|
func (p *userProjection) reduceHumanPasswordChanged(event eventstore.Event) (*handler.Statement, error) {
|
|
|
|
e, ok := event.(*user.HumanPasswordChangedEvent)
|
|
|
|
if !ok {
|
2023-12-08 14:30:55 +00:00
|
|
|
return nil, zerrors.ThrowInvalidArgumentf(nil, "HANDL-jqXUY", "reduce.wrong.event.type %s", user.HumanPasswordChangedType)
|
2022-07-06 12:09:49 +00:00
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
return handler.NewUpdateStatement(
|
2022-07-06 12:09:49 +00:00
|
|
|
e,
|
|
|
|
[]handler.Column{
|
|
|
|
handler.NewCol(NotifyPasswordSetCol, true),
|
|
|
|
},
|
|
|
|
[]handler.Condition{
|
|
|
|
handler.NewCond(NotifyUserIDCol, e.Aggregate().ID),
|
|
|
|
handler.NewCond(NotifyInstanceIDCol, e.Aggregate().InstanceID),
|
|
|
|
},
|
2023-10-19 10:19:10 +00:00
|
|
|
handler.WithTableSuffix(UserNotifySuffix),
|
2022-07-06 12:09:49 +00:00
|
|
|
), nil
|
|
|
|
}
|
|
|
|
|
2023-01-31 19:52:47 +00:00
|
|
|
func (p *userProjection) reduceMachineSecretSet(event eventstore.Event) (*handler.Statement, error) {
|
|
|
|
e, ok := event.(*user.MachineSecretSetEvent)
|
|
|
|
if !ok {
|
2023-12-08 14:30:55 +00:00
|
|
|
return nil, zerrors.ThrowInvalidArgumentf(nil, "HANDL-x0p1n1i", "reduce.wrong.event.type %s", user.MachineSecretSetType)
|
2023-01-31 19:52:47 +00:00
|
|
|
}
|
2023-10-19 10:19:10 +00:00
|
|
|
return handler.NewMultiStatement(
|
2023-01-31 19:52:47 +00:00
|
|
|
e,
|
2023-10-19 10:19:10 +00:00
|
|
|
handler.AddUpdateStatement(
|
2023-01-31 19:52:47 +00:00
|
|
|
[]handler.Column{
|
|
|
|
handler.NewCol(UserChangeDateCol, e.CreationDate()),
|
|
|
|
handler.NewCol(UserSequenceCol, e.Sequence()),
|
|
|
|
},
|
|
|
|
[]handler.Condition{
|
|
|
|
handler.NewCond(UserIDCol, e.Aggregate().ID),
|
|
|
|
handler.NewCond(UserInstanceIDCol, e.Aggregate().InstanceID),
|
|
|
|
},
|
|
|
|
),
|
2023-10-19 10:19:10 +00:00
|
|
|
handler.AddUpdateStatement(
|
2023-01-31 19:52:47 +00:00
|
|
|
[]handler.Column{
|
2023-12-05 17:01:03 +00:00
|
|
|
handler.NewCol(MachineSecretCol, e.ClientSecret),
|
2023-01-31 19:52:47 +00:00
|
|
|
},
|
|
|
|
[]handler.Condition{
|
|
|
|
handler.NewCond(MachineUserIDCol, e.Aggregate().ID),
|
|
|
|
handler.NewCond(MachineUserInstanceIDCol, e.Aggregate().InstanceID),
|
|
|
|
},
|
2023-10-19 10:19:10 +00:00
|
|
|
handler.WithTableSuffix(UserMachineSuffix),
|
2023-01-31 19:52:47 +00:00
|
|
|
),
|
|
|
|
), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *userProjection) reduceMachineSecretRemoved(event eventstore.Event) (*handler.Statement, error) {
|
|
|
|
e, ok := event.(*user.MachineSecretRemovedEvent)
|
|
|
|
if !ok {
|
2023-12-08 14:30:55 +00:00
|
|
|
return nil, zerrors.ThrowInvalidArgumentf(nil, "HANDL-x0p6n1i", "reduce.wrong.event.type %s", user.MachineSecretRemovedType)
|
2023-01-31 19:52:47 +00:00
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
return handler.NewMultiStatement(
|
2023-01-31 19:52:47 +00:00
|
|
|
e,
|
2023-10-19 10:19:10 +00:00
|
|
|
handler.AddUpdateStatement(
|
2023-01-31 19:52:47 +00:00
|
|
|
[]handler.Column{
|
|
|
|
handler.NewCol(UserChangeDateCol, e.CreationDate()),
|
|
|
|
handler.NewCol(UserSequenceCol, e.Sequence()),
|
|
|
|
},
|
|
|
|
[]handler.Condition{
|
|
|
|
handler.NewCond(UserIDCol, e.Aggregate().ID),
|
|
|
|
handler.NewCond(UserInstanceIDCol, e.Aggregate().InstanceID),
|
|
|
|
},
|
|
|
|
),
|
2023-10-19 10:19:10 +00:00
|
|
|
handler.AddUpdateStatement(
|
2023-01-31 19:52:47 +00:00
|
|
|
[]handler.Column{
|
2023-12-05 17:01:03 +00:00
|
|
|
handler.NewCol(MachineSecretCol, nil),
|
2023-01-31 19:52:47 +00:00
|
|
|
},
|
|
|
|
[]handler.Condition{
|
|
|
|
handler.NewCond(MachineUserIDCol, e.Aggregate().ID),
|
|
|
|
handler.NewCond(MachineUserInstanceIDCol, e.Aggregate().InstanceID),
|
|
|
|
},
|
2023-10-19 10:19:10 +00:00
|
|
|
handler.WithTableSuffix(UserMachineSuffix),
|
2023-01-31 19:52:47 +00:00
|
|
|
),
|
|
|
|
), nil
|
|
|
|
}
|
|
|
|
|
2022-06-14 05:51:00 +00:00
|
|
|
func (p *userProjection) reduceMachineAdded(event eventstore.Event) (*handler.Statement, error) {
|
2021-11-30 07:57:51 +00:00
|
|
|
e, ok := event.(*user.MachineAddedEvent)
|
|
|
|
if !ok {
|
2023-12-08 14:30:55 +00:00
|
|
|
return nil, zerrors.ThrowInvalidArgumentf(nil, "HANDL-q7ier", "reduce.wrong.event.type %s", user.MachineAddedEventType)
|
2021-11-30 07:57:51 +00:00
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
return handler.NewMultiStatement(
|
2021-11-30 07:57:51 +00:00
|
|
|
e,
|
2023-10-19 10:19:10 +00:00
|
|
|
handler.AddCreateStatement(
|
2021-11-30 07:57:51 +00:00
|
|
|
[]handler.Column{
|
|
|
|
handler.NewCol(UserIDCol, e.Aggregate().ID),
|
|
|
|
handler.NewCol(UserCreationDateCol, e.CreationDate()),
|
|
|
|
handler.NewCol(UserChangeDateCol, e.CreationDate()),
|
|
|
|
handler.NewCol(UserResourceOwnerCol, e.Aggregate().ResourceOwner),
|
2022-03-23 08:02:39 +00:00
|
|
|
handler.NewCol(UserInstanceIDCol, e.Aggregate().InstanceID),
|
2022-01-25 10:35:38 +00:00
|
|
|
handler.NewCol(UserStateCol, domain.UserStateActive),
|
2021-11-30 07:57:51 +00:00
|
|
|
handler.NewCol(UserSequenceCol, e.Sequence()),
|
|
|
|
handler.NewCol(UserUsernameCol, e.UserName),
|
2022-01-14 09:45:50 +00:00
|
|
|
handler.NewCol(UserTypeCol, domain.UserTypeMachine),
|
2021-11-30 07:57:51 +00:00
|
|
|
},
|
|
|
|
),
|
2023-10-19 10:19:10 +00:00
|
|
|
handler.AddCreateStatement(
|
2021-11-30 07:57:51 +00:00
|
|
|
[]handler.Column{
|
|
|
|
handler.NewCol(MachineUserIDCol, e.Aggregate().ID),
|
2022-05-25 12:15:13 +00:00
|
|
|
handler.NewCol(MachineUserInstanceIDCol, e.Aggregate().InstanceID),
|
2021-11-30 07:57:51 +00:00
|
|
|
handler.NewCol(MachineNameCol, e.Name),
|
|
|
|
handler.NewCol(MachineDescriptionCol, &sql.NullString{String: e.Description, Valid: e.Description != ""}),
|
2023-02-08 08:06:34 +00:00
|
|
|
handler.NewCol(MachineAccessTokenTypeCol, e.AccessTokenType),
|
2021-11-30 07:57:51 +00:00
|
|
|
},
|
2023-10-19 10:19:10 +00:00
|
|
|
handler.WithTableSuffix(UserMachineSuffix),
|
2021-11-30 07:57:51 +00:00
|
|
|
),
|
|
|
|
), nil
|
|
|
|
}
|
|
|
|
|
2022-06-14 05:51:00 +00:00
|
|
|
func (p *userProjection) reduceMachineChanged(event eventstore.Event) (*handler.Statement, error) {
|
2021-11-30 07:57:51 +00:00
|
|
|
e, ok := event.(*user.MachineChangedEvent)
|
|
|
|
if !ok {
|
2023-12-08 14:30:55 +00:00
|
|
|
return nil, zerrors.ThrowInvalidArgumentf(nil, "HANDL-qYHvj", "reduce.wrong.event.type %s", user.MachineChangedEventType)
|
2021-11-30 07:57:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
cols := make([]handler.Column, 0, 2)
|
|
|
|
if e.Name != nil {
|
|
|
|
cols = append(cols, handler.NewCol(MachineNameCol, *e.Name))
|
|
|
|
}
|
|
|
|
if e.Description != nil {
|
|
|
|
cols = append(cols, handler.NewCol(MachineDescriptionCol, *e.Description))
|
|
|
|
}
|
2023-02-08 08:06:34 +00:00
|
|
|
if e.AccessTokenType != nil {
|
|
|
|
cols = append(cols, handler.NewCol(MachineAccessTokenTypeCol, e.AccessTokenType))
|
|
|
|
}
|
2021-11-30 07:57:51 +00:00
|
|
|
if len(cols) == 0 {
|
2023-10-19 10:19:10 +00:00
|
|
|
return handler.NewNoOpStatement(e), nil
|
2021-11-30 07:57:51 +00:00
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
return handler.NewMultiStatement(
|
2021-11-30 07:57:51 +00:00
|
|
|
e,
|
2023-10-19 10:19:10 +00:00
|
|
|
handler.AddUpdateStatement(
|
2021-11-30 07:57:51 +00:00
|
|
|
[]handler.Column{
|
|
|
|
handler.NewCol(UserChangeDateCol, e.CreationDate()),
|
|
|
|
handler.NewCol(UserSequenceCol, e.Sequence()),
|
|
|
|
},
|
|
|
|
[]handler.Condition{
|
|
|
|
handler.NewCond(UserIDCol, e.Aggregate().ID),
|
2022-05-25 12:15:13 +00:00
|
|
|
handler.NewCond(UserInstanceIDCol, e.Aggregate().InstanceID),
|
2021-11-30 07:57:51 +00:00
|
|
|
},
|
|
|
|
),
|
2023-10-19 10:19:10 +00:00
|
|
|
handler.AddUpdateStatement(
|
2021-11-30 07:57:51 +00:00
|
|
|
cols,
|
|
|
|
[]handler.Condition{
|
|
|
|
handler.NewCond(MachineUserIDCol, e.Aggregate().ID),
|
2022-05-25 12:15:13 +00:00
|
|
|
handler.NewCond(MachineUserInstanceIDCol, e.Aggregate().InstanceID),
|
2021-11-30 07:57:51 +00:00
|
|
|
},
|
2023-10-19 10:19:10 +00:00
|
|
|
handler.WithTableSuffix(UserMachineSuffix),
|
2021-11-30 07:57:51 +00:00
|
|
|
),
|
|
|
|
), nil
|
2022-11-30 16:01:17 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *userProjection) reduceOwnerRemoved(event eventstore.Event) (*handler.Statement, error) {
|
|
|
|
e, ok := event.(*org.OrgRemovedEvent)
|
|
|
|
if !ok {
|
2023-12-08 14:30:55 +00:00
|
|
|
return nil, zerrors.ThrowInvalidArgumentf(nil, "PROJE-NCsdV", "reduce.wrong.event.type %s", org.OrgRemovedEventType)
|
2022-11-30 16:01:17 +00:00
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
return handler.NewDeleteStatement(
|
2022-11-30 16:01:17 +00:00
|
|
|
e,
|
|
|
|
[]handler.Condition{
|
|
|
|
handler.NewCond(UserInstanceIDCol, e.Aggregate().InstanceID),
|
|
|
|
handler.NewCond(UserResourceOwnerCol, e.Aggregate().ID),
|
|
|
|
},
|
|
|
|
), nil
|
2021-11-30 07:57:51 +00:00
|
|
|
}
|