mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-14 20:08:02 +00:00
58 lines
1.1 KiB
Go
58 lines
1.1 KiB
Go
|
package projection
|
||
|
|
||
|
import (
|
||
|
"github.com/zitadel/zitadel/internal/v2/eventstore"
|
||
|
"github.com/zitadel/zitadel/internal/v2/org"
|
||
|
)
|
||
|
|
||
|
type OrgPrimaryDomain struct {
|
||
|
projection
|
||
|
|
||
|
id string
|
||
|
|
||
|
Domain string
|
||
|
}
|
||
|
|
||
|
func NewOrgPrimaryDomain(id string) *OrgPrimaryDomain {
|
||
|
return &OrgPrimaryDomain{
|
||
|
id: id,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func (p *OrgPrimaryDomain) Filter() []*eventstore.Filter {
|
||
|
return []*eventstore.Filter{
|
||
|
eventstore.NewFilter(
|
||
|
eventstore.FilterPagination(
|
||
|
eventstore.GlobalPositionGreater(&p.position),
|
||
|
),
|
||
|
eventstore.AppendAggregateFilter(
|
||
|
org.AggregateType,
|
||
|
eventstore.AggregateIDs(p.id),
|
||
|
eventstore.AppendEvent(
|
||
|
eventstore.SetEventTypes(org.DomainPrimarySetType),
|
||
|
),
|
||
|
),
|
||
|
),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func (p *OrgPrimaryDomain) Reduce(events ...*eventstore.StorageEvent) error {
|
||
|
for _, event := range events {
|
||
|
if !p.shouldReduce(event) {
|
||
|
continue
|
||
|
}
|
||
|
if event.Type != org.DomainPrimarySetType {
|
||
|
continue
|
||
|
}
|
||
|
e, err := org.DomainPrimarySetEventFromStorage(event)
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
|
||
|
p.Domain = e.Payload.Name
|
||
|
p.projection.reduce(event)
|
||
|
}
|
||
|
|
||
|
return nil
|
||
|
}
|