2022-02-21 12:22:20 +00:00
|
|
|
package projection
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
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-04-26 23:01:45 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/repository/instance"
|
2022-02-21 12:22:20 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2024-09-06 13:11:36 +00:00
|
|
|
SMSConfigProjectionTable = "projections.sms_configs3"
|
2022-02-21 12:22:20 +00:00
|
|
|
SMSTwilioTable = SMSConfigProjectionTable + "_" + smsTwilioTableSuffix
|
2024-09-06 13:11:36 +00:00
|
|
|
SMSHTTPTable = SMSConfigProjectionTable + "_" + smsHTTPTableSuffix
|
2022-03-23 08:02:39 +00:00
|
|
|
|
|
|
|
SMSColumnID = "id"
|
|
|
|
SMSColumnAggregateID = "aggregate_id"
|
|
|
|
SMSColumnCreationDate = "creation_date"
|
|
|
|
SMSColumnChangeDate = "change_date"
|
|
|
|
SMSColumnSequence = "sequence"
|
|
|
|
SMSColumnState = "state"
|
|
|
|
SMSColumnResourceOwner = "resource_owner"
|
|
|
|
SMSColumnInstanceID = "instance_id"
|
2024-09-06 13:11:36 +00:00
|
|
|
SMSColumnDescription = "description"
|
2022-03-23 08:02:39 +00:00
|
|
|
|
2024-09-06 13:11:36 +00:00
|
|
|
smsTwilioTableSuffix = "twilio"
|
|
|
|
SMSTwilioColumnSMSID = "sms_id"
|
|
|
|
SMSTwilioColumnInstanceID = "instance_id"
|
|
|
|
SMSTwilioColumnSID = "sid"
|
|
|
|
SMSTwilioColumnSenderNumber = "sender_number"
|
|
|
|
SMSTwilioColumnToken = "token"
|
|
|
|
|
|
|
|
smsHTTPTableSuffix = "http"
|
|
|
|
SMSHTTPColumnSMSID = "sms_id"
|
|
|
|
SMSHTTPColumnInstanceID = "instance_id"
|
|
|
|
SMSHTTPColumnEndpoint = "endpoint"
|
2022-02-21 12:22:20 +00:00
|
|
|
)
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
type smsConfigProjection struct{}
|
|
|
|
|
|
|
|
func newSMSConfigProjection(ctx context.Context, config handler.Config) *handler.Handler {
|
|
|
|
return handler.NewHandler(ctx, &config, new(smsConfigProjection))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (*smsConfigProjection) Name() string {
|
|
|
|
return SMSConfigProjectionTable
|
2022-03-23 08:02:39 +00:00
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func (*smsConfigProjection) Init() *old_handler.Check {
|
|
|
|
return handler.NewMultiTableCheck(
|
|
|
|
handler.NewTable([]*handler.InitColumn{
|
|
|
|
handler.NewColumn(SMSColumnID, handler.ColumnTypeText),
|
|
|
|
handler.NewColumn(SMSColumnAggregateID, handler.ColumnTypeText),
|
|
|
|
handler.NewColumn(SMSColumnCreationDate, handler.ColumnTypeTimestamp),
|
|
|
|
handler.NewColumn(SMSColumnChangeDate, handler.ColumnTypeTimestamp),
|
|
|
|
handler.NewColumn(SMSColumnSequence, handler.ColumnTypeInt64),
|
|
|
|
handler.NewColumn(SMSColumnState, handler.ColumnTypeEnum),
|
|
|
|
handler.NewColumn(SMSColumnResourceOwner, handler.ColumnTypeText),
|
|
|
|
handler.NewColumn(SMSColumnInstanceID, handler.ColumnTypeText),
|
2024-09-06 13:11:36 +00:00
|
|
|
handler.NewColumn(SMSColumnDescription, handler.ColumnTypeText),
|
2022-03-23 08:02:39 +00:00
|
|
|
},
|
2023-10-19 10:19:10 +00:00
|
|
|
handler.NewPrimaryKey(SMSColumnInstanceID, SMSColumnID),
|
2022-03-23 08:02:39 +00:00
|
|
|
),
|
2023-10-19 10:19:10 +00:00
|
|
|
handler.NewSuffixedTable([]*handler.InitColumn{
|
2024-09-06 13:11:36 +00:00
|
|
|
handler.NewColumn(SMSTwilioColumnSMSID, handler.ColumnTypeText),
|
2023-10-19 10:19:10 +00:00
|
|
|
handler.NewColumn(SMSTwilioColumnInstanceID, handler.ColumnTypeText),
|
2024-09-06 13:11:36 +00:00
|
|
|
handler.NewColumn(SMSTwilioColumnSID, handler.ColumnTypeText),
|
|
|
|
handler.NewColumn(SMSTwilioColumnSenderNumber, handler.ColumnTypeText),
|
|
|
|
handler.NewColumn(SMSTwilioColumnToken, handler.ColumnTypeJSONB),
|
2022-03-23 08:02:39 +00:00
|
|
|
},
|
2024-09-06 13:11:36 +00:00
|
|
|
handler.NewPrimaryKey(SMSTwilioColumnInstanceID, SMSTwilioColumnSMSID),
|
2022-03-23 08:02:39 +00:00
|
|
|
smsTwilioTableSuffix,
|
2023-10-19 10:19:10 +00:00
|
|
|
handler.WithForeignKey(handler.NewForeignKeyOfPublicKeys()),
|
2022-03-23 08:02:39 +00:00
|
|
|
),
|
2024-09-06 13:11:36 +00:00
|
|
|
handler.NewSuffixedTable([]*handler.InitColumn{
|
|
|
|
handler.NewColumn(SMSHTTPColumnSMSID, handler.ColumnTypeText),
|
|
|
|
handler.NewColumn(SMSHTTPColumnInstanceID, handler.ColumnTypeText),
|
|
|
|
handler.NewColumn(SMSHTTPColumnEndpoint, handler.ColumnTypeText),
|
|
|
|
},
|
|
|
|
handler.NewPrimaryKey(SMSHTTPColumnInstanceID, SMSHTTPColumnSMSID),
|
|
|
|
smsHTTPTableSuffix,
|
|
|
|
handler.WithForeignKey(handler.NewForeignKeyOfPublicKeys()),
|
|
|
|
),
|
2022-03-23 08:02:39 +00:00
|
|
|
)
|
2022-02-21 12:22:20 +00:00
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func (p *smsConfigProjection) Reducers() []handler.AggregateReducer {
|
2022-02-21 12:22:20 +00:00
|
|
|
return []handler.AggregateReducer{
|
|
|
|
{
|
2022-03-24 16:21:34 +00:00
|
|
|
Aggregate: instance.AggregateType,
|
2023-10-19 10:19:10 +00:00
|
|
|
EventReducers: []handler.EventReducer{
|
2022-02-21 12:22:20 +00:00
|
|
|
{
|
2022-03-24 16:21:34 +00:00
|
|
|
Event: instance.SMSConfigTwilioAddedEventType,
|
2022-02-21 12:22:20 +00:00
|
|
|
Reduce: p.reduceSMSConfigTwilioAdded,
|
|
|
|
},
|
|
|
|
{
|
2022-03-24 16:21:34 +00:00
|
|
|
Event: instance.SMSConfigTwilioChangedEventType,
|
2022-02-21 12:22:20 +00:00
|
|
|
Reduce: p.reduceSMSConfigTwilioChanged,
|
|
|
|
},
|
2022-06-13 06:34:11 +00:00
|
|
|
{
|
|
|
|
Event: instance.SMSConfigTwilioTokenChangedEventType,
|
|
|
|
Reduce: p.reduceSMSConfigTwilioTokenChanged,
|
|
|
|
},
|
2024-09-06 13:11:36 +00:00
|
|
|
{
|
|
|
|
Event: instance.SMSConfigHTTPAddedEventType,
|
|
|
|
Reduce: p.reduceSMSConfigHTTPAdded,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Event: instance.SMSConfigHTTPChangedEventType,
|
|
|
|
Reduce: p.reduceSMSConfigHTTPChanged,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Event: instance.SMSConfigTwilioActivatedEventType,
|
|
|
|
Reduce: p.reduceSMSConfigTwilioActivated,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Event: instance.SMSConfigTwilioDeactivatedEventType,
|
|
|
|
Reduce: p.reduceSMSConfigTwilioDeactivated,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Event: instance.SMSConfigTwilioRemovedEventType,
|
|
|
|
Reduce: p.reduceSMSConfigTwilioRemoved,
|
|
|
|
},
|
2022-02-21 12:22:20 +00:00
|
|
|
{
|
2022-03-24 16:21:34 +00:00
|
|
|
Event: instance.SMSConfigActivatedEventType,
|
2022-02-21 12:22:20 +00:00
|
|
|
Reduce: p.reduceSMSConfigActivated,
|
|
|
|
},
|
|
|
|
{
|
2022-03-24 16:21:34 +00:00
|
|
|
Event: instance.SMSConfigDeactivatedEventType,
|
2022-02-21 12:22:20 +00:00
|
|
|
Reduce: p.reduceSMSConfigDeactivated,
|
|
|
|
},
|
|
|
|
{
|
2022-03-24 16:21:34 +00:00
|
|
|
Event: instance.SMSConfigRemovedEventType,
|
2022-02-21 12:22:20 +00:00
|
|
|
Reduce: p.reduceSMSConfigRemoved,
|
|
|
|
},
|
2022-10-20 12:36:52 +00:00
|
|
|
{
|
|
|
|
Event: instance.InstanceRemovedEventType,
|
|
|
|
Reduce: reduceInstanceRemovedHelper(SMSColumnInstanceID),
|
|
|
|
},
|
2022-02-21 12:22:20 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-14 05:51:00 +00:00
|
|
|
func (p *smsConfigProjection) reduceSMSConfigTwilioAdded(event eventstore.Event) (*handler.Statement, error) {
|
2024-09-06 13:11:36 +00:00
|
|
|
e, err := assertEvent[*instance.SMSConfigTwilioAddedEvent](event)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2022-02-21 12:22:20 +00:00
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
return handler.NewMultiStatement(
|
2022-02-21 12:22:20 +00:00
|
|
|
e,
|
2023-10-19 10:19:10 +00:00
|
|
|
handler.AddCreateStatement(
|
2022-02-21 12:22:20 +00:00
|
|
|
[]handler.Column{
|
|
|
|
handler.NewCol(SMSColumnID, e.ID),
|
|
|
|
handler.NewCol(SMSColumnAggregateID, e.Aggregate().ID),
|
|
|
|
handler.NewCol(SMSColumnCreationDate, e.CreationDate()),
|
|
|
|
handler.NewCol(SMSColumnChangeDate, e.CreationDate()),
|
|
|
|
handler.NewCol(SMSColumnResourceOwner, e.Aggregate().ResourceOwner),
|
2022-03-23 08:02:39 +00:00
|
|
|
handler.NewCol(SMSColumnInstanceID, e.Aggregate().InstanceID),
|
2022-02-21 12:22:20 +00:00
|
|
|
handler.NewCol(SMSColumnState, domain.SMSConfigStateInactive),
|
|
|
|
handler.NewCol(SMSColumnSequence, e.Sequence()),
|
2024-09-06 13:11:36 +00:00
|
|
|
handler.NewCol(SMSColumnDescription, e.Description),
|
2022-02-21 12:22:20 +00:00
|
|
|
},
|
|
|
|
),
|
2023-10-19 10:19:10 +00:00
|
|
|
handler.AddCreateStatement(
|
2022-02-21 12:22:20 +00:00
|
|
|
[]handler.Column{
|
2024-09-06 13:11:36 +00:00
|
|
|
handler.NewCol(SMSTwilioColumnSMSID, e.ID),
|
2022-05-25 12:15:13 +00:00
|
|
|
handler.NewCol(SMSTwilioColumnInstanceID, e.Aggregate().InstanceID),
|
2024-09-06 13:11:36 +00:00
|
|
|
handler.NewCol(SMSTwilioColumnSID, e.SID),
|
|
|
|
handler.NewCol(SMSTwilioColumnToken, e.Token),
|
|
|
|
handler.NewCol(SMSTwilioColumnSenderNumber, e.SenderNumber),
|
2022-02-21 12:22:20 +00:00
|
|
|
},
|
2023-10-19 10:19:10 +00:00
|
|
|
handler.WithTableSuffix(smsTwilioTableSuffix),
|
2022-02-21 12:22:20 +00:00
|
|
|
),
|
|
|
|
), nil
|
|
|
|
}
|
|
|
|
|
2022-06-14 05:51:00 +00:00
|
|
|
func (p *smsConfigProjection) reduceSMSConfigTwilioChanged(event eventstore.Event) (*handler.Statement, error) {
|
2024-09-06 13:11:36 +00:00
|
|
|
e, err := assertEvent[*instance.SMSConfigTwilioChangedEvent](event)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
stmts := make([]func(eventstore.Event) handler.Exec, 0, 3)
|
|
|
|
columns := []handler.Column{
|
|
|
|
handler.NewCol(SMSColumnChangeDate, e.CreationDate()),
|
|
|
|
handler.NewCol(SMSColumnSequence, e.Sequence()),
|
2022-02-21 12:22:20 +00:00
|
|
|
}
|
2024-09-06 13:11:36 +00:00
|
|
|
if e.Description != nil {
|
|
|
|
columns = append(columns, handler.NewCol(SMSColumnDescription, *e.Description))
|
|
|
|
}
|
|
|
|
if len(columns) > 0 {
|
|
|
|
stmts = append(stmts, handler.AddUpdateStatement(
|
|
|
|
columns,
|
|
|
|
[]handler.Condition{
|
|
|
|
handler.NewCond(SMSColumnID, e.ID),
|
|
|
|
handler.NewCond(SMSColumnInstanceID, e.Aggregate().InstanceID),
|
|
|
|
},
|
|
|
|
))
|
|
|
|
}
|
|
|
|
|
|
|
|
twilioColumns := make([]handler.Column, 0)
|
2022-02-21 12:22:20 +00:00
|
|
|
if e.SID != nil {
|
2024-09-06 13:11:36 +00:00
|
|
|
twilioColumns = append(twilioColumns, handler.NewCol(SMSTwilioColumnSID, *e.SID))
|
2022-02-21 12:22:20 +00:00
|
|
|
}
|
|
|
|
if e.SenderNumber != nil {
|
2024-09-06 13:11:36 +00:00
|
|
|
twilioColumns = append(twilioColumns, handler.NewCol(SMSTwilioColumnSenderNumber, *e.SenderNumber))
|
|
|
|
}
|
|
|
|
if len(twilioColumns) > 0 {
|
|
|
|
stmts = append(stmts, handler.AddUpdateStatement(
|
|
|
|
twilioColumns,
|
|
|
|
[]handler.Condition{
|
|
|
|
handler.NewCond(SMSTwilioColumnSMSID, e.ID),
|
|
|
|
handler.NewCond(SMSTwilioColumnInstanceID, e.Aggregate().InstanceID),
|
|
|
|
},
|
|
|
|
handler.WithTableSuffix(smsTwilioTableSuffix),
|
|
|
|
))
|
|
|
|
}
|
|
|
|
|
|
|
|
return handler.NewMultiStatement(e, stmts...), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *smsConfigProjection) reduceSMSConfigTwilioTokenChanged(event eventstore.Event) (*handler.Statement, error) {
|
|
|
|
e, err := assertEvent[*instance.SMSConfigTwilioTokenChangedEvent](event)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2022-06-13 06:34:11 +00:00
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
return handler.NewMultiStatement(
|
2022-06-13 06:34:11 +00:00
|
|
|
e,
|
2023-10-19 10:19:10 +00:00
|
|
|
handler.AddUpdateStatement(
|
2024-09-06 13:11:36 +00:00
|
|
|
[]handler.Column{
|
|
|
|
handler.NewCol(SMSTwilioColumnToken, e.Token),
|
|
|
|
},
|
2022-06-13 06:34:11 +00:00
|
|
|
[]handler.Condition{
|
2024-09-06 13:11:36 +00:00
|
|
|
handler.NewCond(SMSTwilioColumnSMSID, e.ID),
|
2022-06-13 06:34:11 +00:00
|
|
|
handler.NewCond(SMSTwilioColumnInstanceID, e.Aggregate().InstanceID),
|
|
|
|
},
|
2023-10-19 10:19:10 +00:00
|
|
|
handler.WithTableSuffix(smsTwilioTableSuffix),
|
2022-06-13 06:34:11 +00:00
|
|
|
),
|
2023-10-19 10:19:10 +00:00
|
|
|
handler.AddUpdateStatement(
|
2022-06-13 06:34:11 +00:00
|
|
|
[]handler.Column{
|
|
|
|
handler.NewCol(SMSColumnChangeDate, e.CreationDate()),
|
|
|
|
handler.NewCol(SMSColumnSequence, e.Sequence()),
|
|
|
|
},
|
|
|
|
[]handler.Condition{
|
|
|
|
handler.NewCond(SMSColumnID, e.ID),
|
|
|
|
handler.NewCond(SMSColumnInstanceID, e.Aggregate().InstanceID),
|
|
|
|
},
|
|
|
|
),
|
|
|
|
), nil
|
|
|
|
}
|
|
|
|
|
2024-09-06 13:11:36 +00:00
|
|
|
func (p *smsConfigProjection) reduceSMSConfigHTTPAdded(event eventstore.Event) (*handler.Statement, error) {
|
|
|
|
e, err := assertEvent[*instance.SMSConfigHTTPAddedEvent](event)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2022-06-13 06:34:11 +00:00
|
|
|
}
|
2024-09-06 13:11:36 +00:00
|
|
|
|
|
|
|
return handler.NewMultiStatement(
|
|
|
|
e,
|
|
|
|
handler.AddCreateStatement(
|
|
|
|
[]handler.Column{
|
|
|
|
handler.NewCol(SMSColumnID, e.ID),
|
|
|
|
handler.NewCol(SMSColumnAggregateID, e.Aggregate().ID),
|
|
|
|
handler.NewCol(SMSColumnCreationDate, e.CreationDate()),
|
|
|
|
handler.NewCol(SMSColumnChangeDate, e.CreationDate()),
|
|
|
|
handler.NewCol(SMSColumnResourceOwner, e.Aggregate().ResourceOwner),
|
|
|
|
handler.NewCol(SMSColumnInstanceID, e.Aggregate().InstanceID),
|
|
|
|
handler.NewCol(SMSColumnState, domain.SMSConfigStateInactive),
|
|
|
|
handler.NewCol(SMSColumnSequence, e.Sequence()),
|
|
|
|
handler.NewCol(SMSColumnDescription, e.Description),
|
|
|
|
},
|
|
|
|
),
|
|
|
|
handler.AddCreateStatement(
|
|
|
|
[]handler.Column{
|
|
|
|
handler.NewCol(SMSHTTPColumnSMSID, e.ID),
|
|
|
|
handler.NewCol(SMSHTTPColumnInstanceID, e.Aggregate().InstanceID),
|
|
|
|
handler.NewCol(SMSHTTPColumnEndpoint, e.Endpoint),
|
|
|
|
},
|
|
|
|
handler.WithTableSuffix(smsHTTPTableSuffix),
|
|
|
|
),
|
|
|
|
), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *smsConfigProjection) reduceSMSConfigHTTPChanged(event eventstore.Event) (*handler.Statement, error) {
|
|
|
|
e, err := assertEvent[*instance.SMSConfigHTTPChangedEvent](event)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
stmts := make([]func(eventstore.Event) handler.Exec, 0, 3)
|
|
|
|
columns := []handler.Column{
|
|
|
|
handler.NewCol(SMSColumnChangeDate, e.CreationDate()),
|
|
|
|
handler.NewCol(SMSColumnSequence, e.Sequence()),
|
|
|
|
}
|
|
|
|
if e.Description != nil {
|
|
|
|
columns = append(columns, handler.NewCol(SMSColumnDescription, *e.Description))
|
|
|
|
}
|
|
|
|
if len(columns) > 0 {
|
|
|
|
stmts = append(stmts, handler.AddUpdateStatement(
|
|
|
|
columns,
|
|
|
|
[]handler.Condition{
|
|
|
|
handler.NewCond(SMSColumnID, e.ID),
|
|
|
|
handler.NewCond(SMSColumnInstanceID, e.Aggregate().InstanceID),
|
|
|
|
},
|
|
|
|
))
|
|
|
|
}
|
|
|
|
|
|
|
|
if e.Endpoint != nil {
|
|
|
|
stmts = append(stmts, handler.AddUpdateStatement(
|
|
|
|
[]handler.Column{
|
|
|
|
handler.NewCol(SMSHTTPColumnEndpoint, *e.Endpoint),
|
|
|
|
},
|
|
|
|
[]handler.Condition{
|
|
|
|
handler.NewCond(SMSHTTPColumnSMSID, e.ID),
|
|
|
|
handler.NewCond(SMSHTTPColumnInstanceID, e.Aggregate().InstanceID),
|
|
|
|
},
|
|
|
|
handler.WithTableSuffix(smsHTTPTableSuffix),
|
|
|
|
))
|
|
|
|
}
|
|
|
|
|
|
|
|
return handler.NewMultiStatement(e, stmts...), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *smsConfigProjection) reduceSMSConfigTwilioActivated(event eventstore.Event) (*handler.Statement, error) {
|
|
|
|
e, err := assertEvent[*instance.SMSConfigTwilioActivatedEvent](event)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2022-02-21 12:22:20 +00:00
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
return handler.NewMultiStatement(
|
2022-02-21 12:22:20 +00:00
|
|
|
e,
|
2023-10-19 10:19:10 +00:00
|
|
|
handler.AddUpdateStatement(
|
2024-09-06 13:11:36 +00:00
|
|
|
[]handler.Column{
|
|
|
|
handler.NewCol(SMSColumnState, domain.SMSConfigStateInactive),
|
|
|
|
handler.NewCol(SMSColumnChangeDate, e.CreationDate()),
|
|
|
|
handler.NewCol(SMSColumnSequence, e.Sequence()),
|
|
|
|
},
|
2022-02-21 12:22:20 +00:00
|
|
|
[]handler.Condition{
|
2024-09-06 13:11:36 +00:00
|
|
|
handler.Not(handler.NewCond(SMSColumnID, e.ID)),
|
|
|
|
handler.NewCond(SMSColumnState, domain.SMSConfigStateActive),
|
|
|
|
handler.NewCond(SMSColumnInstanceID, e.Aggregate().InstanceID),
|
2022-02-21 12:22:20 +00:00
|
|
|
},
|
|
|
|
),
|
2023-10-19 10:19:10 +00:00
|
|
|
handler.AddUpdateStatement(
|
2022-02-21 12:22:20 +00:00
|
|
|
[]handler.Column{
|
2024-09-06 13:11:36 +00:00
|
|
|
handler.NewCol(SMSColumnState, domain.SMSConfigStateActive),
|
2022-02-21 12:22:20 +00:00
|
|
|
handler.NewCol(SMSColumnChangeDate, e.CreationDate()),
|
|
|
|
handler.NewCol(SMSColumnSequence, e.Sequence()),
|
|
|
|
},
|
|
|
|
[]handler.Condition{
|
|
|
|
handler.NewCond(SMSColumnID, e.ID),
|
2022-05-25 12:15:13 +00:00
|
|
|
handler.NewCond(SMSColumnInstanceID, e.Aggregate().InstanceID),
|
2022-02-21 12:22:20 +00:00
|
|
|
},
|
|
|
|
),
|
|
|
|
), nil
|
|
|
|
}
|
|
|
|
|
2024-09-06 13:11:36 +00:00
|
|
|
func (p *smsConfigProjection) reduceSMSConfigTwilioDeactivated(event eventstore.Event) (*handler.Statement, error) {
|
|
|
|
e, err := assertEvent[*instance.SMSConfigTwilioDeactivatedEvent](event)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2022-02-21 12:22:20 +00:00
|
|
|
}
|
2024-09-06 13:11:36 +00:00
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
return handler.NewUpdateStatement(
|
2022-02-21 12:22:20 +00:00
|
|
|
e,
|
|
|
|
[]handler.Column{
|
2024-09-06 13:11:36 +00:00
|
|
|
handler.NewCol(SMSColumnState, domain.SMSConfigStateInactive),
|
2022-02-21 12:22:20 +00:00
|
|
|
handler.NewCol(SMSColumnChangeDate, e.CreationDate()),
|
|
|
|
handler.NewCol(SMSColumnSequence, e.Sequence()),
|
|
|
|
},
|
|
|
|
[]handler.Condition{
|
|
|
|
handler.NewCond(SMSColumnID, e.ID),
|
2022-05-25 12:15:13 +00:00
|
|
|
handler.NewCond(SMSColumnInstanceID, e.Aggregate().InstanceID),
|
2022-02-21 12:22:20 +00:00
|
|
|
},
|
|
|
|
), nil
|
|
|
|
}
|
|
|
|
|
2024-09-06 13:11:36 +00:00
|
|
|
func (p *smsConfigProjection) reduceSMSConfigTwilioRemoved(event eventstore.Event) (*handler.Statement, error) {
|
|
|
|
e, err := assertEvent[*instance.SMSConfigTwilioRemovedEvent](event)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return handler.NewDeleteStatement(
|
|
|
|
e,
|
|
|
|
[]handler.Condition{
|
|
|
|
handler.NewCond(SMSColumnID, e.ID),
|
|
|
|
handler.NewCond(SMSColumnInstanceID, e.Aggregate().InstanceID),
|
|
|
|
},
|
|
|
|
), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *smsConfigProjection) reduceSMSConfigActivated(event eventstore.Event) (*handler.Statement, error) {
|
|
|
|
e, err := assertEvent[*instance.SMSConfigActivatedEvent](event)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return handler.NewMultiStatement(
|
|
|
|
e,
|
|
|
|
handler.AddUpdateStatement(
|
|
|
|
[]handler.Column{
|
|
|
|
handler.NewCol(SMSColumnState, domain.SMSConfigStateInactive),
|
|
|
|
handler.NewCol(SMSColumnChangeDate, e.CreationDate()),
|
|
|
|
handler.NewCol(SMSColumnSequence, e.Sequence()),
|
|
|
|
},
|
|
|
|
[]handler.Condition{
|
|
|
|
handler.Not(handler.NewCond(SMSColumnID, e.ID)),
|
|
|
|
handler.NewCond(SMSColumnState, domain.SMSConfigStateActive),
|
|
|
|
handler.NewCond(SMSColumnInstanceID, e.Aggregate().InstanceID),
|
|
|
|
},
|
|
|
|
),
|
|
|
|
handler.AddUpdateStatement(
|
|
|
|
[]handler.Column{
|
|
|
|
handler.NewCol(SMSColumnState, domain.SMSConfigStateActive),
|
|
|
|
handler.NewCol(SMSColumnChangeDate, e.CreationDate()),
|
|
|
|
handler.NewCol(SMSColumnSequence, e.Sequence()),
|
|
|
|
},
|
|
|
|
[]handler.Condition{
|
|
|
|
handler.NewCond(SMSColumnID, e.ID),
|
|
|
|
handler.NewCond(SMSColumnInstanceID, e.Aggregate().InstanceID),
|
|
|
|
},
|
|
|
|
),
|
|
|
|
), nil
|
|
|
|
}
|
|
|
|
|
2022-06-14 05:51:00 +00:00
|
|
|
func (p *smsConfigProjection) reduceSMSConfigDeactivated(event eventstore.Event) (*handler.Statement, error) {
|
2024-09-06 13:11:36 +00:00
|
|
|
e, err := assertEvent[*instance.SMSConfigDeactivatedEvent](event)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2022-02-21 12:22:20 +00:00
|
|
|
}
|
2024-09-06 13:11:36 +00:00
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
return handler.NewUpdateStatement(
|
2022-02-21 12:22:20 +00:00
|
|
|
e,
|
|
|
|
[]handler.Column{
|
|
|
|
handler.NewCol(SMSColumnState, domain.SMSConfigStateInactive),
|
|
|
|
handler.NewCol(SMSColumnChangeDate, e.CreationDate()),
|
|
|
|
handler.NewCol(SMSColumnSequence, e.Sequence()),
|
|
|
|
},
|
|
|
|
[]handler.Condition{
|
|
|
|
handler.NewCond(SMSColumnID, e.ID),
|
2022-05-25 12:15:13 +00:00
|
|
|
handler.NewCond(SMSColumnInstanceID, e.Aggregate().InstanceID),
|
2022-02-21 12:22:20 +00:00
|
|
|
},
|
|
|
|
), nil
|
|
|
|
}
|
|
|
|
|
2022-06-14 05:51:00 +00:00
|
|
|
func (p *smsConfigProjection) reduceSMSConfigRemoved(event eventstore.Event) (*handler.Statement, error) {
|
2024-09-06 13:11:36 +00:00
|
|
|
e, err := assertEvent[*instance.SMSConfigRemovedEvent](event)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2022-02-21 12:22:20 +00:00
|
|
|
}
|
2024-09-06 13:11:36 +00:00
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
return handler.NewDeleteStatement(
|
2022-02-21 12:22:20 +00:00
|
|
|
e,
|
|
|
|
[]handler.Condition{
|
|
|
|
handler.NewCond(SMSColumnID, e.ID),
|
2022-05-25 12:15:13 +00:00
|
|
|
handler.NewCond(SMSColumnInstanceID, e.Aggregate().InstanceID),
|
2022-02-21 12:22:20 +00:00
|
|
|
},
|
|
|
|
), nil
|
|
|
|
}
|