mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-12 00:47:33 +00:00
chore: move the go code into a subfolder
This commit is contained in:
54
apps/api/internal/command/instance_trusted_domains_model.go
Normal file
54
apps/api/internal/command/instance_trusted_domains_model.go
Normal file
@@ -0,0 +1,54 @@
|
||||
package command
|
||||
|
||||
import (
|
||||
"context"
|
||||
"slices"
|
||||
|
||||
"github.com/zitadel/zitadel/internal/api/authz"
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
"github.com/zitadel/zitadel/internal/repository/instance"
|
||||
)
|
||||
|
||||
type InstanceTrustedDomainsWriteModel struct {
|
||||
eventstore.WriteModel
|
||||
|
||||
Domains []string
|
||||
}
|
||||
|
||||
func NewInstanceTrustedDomainsWriteModel(ctx context.Context) *InstanceTrustedDomainsWriteModel {
|
||||
instanceID := authz.GetInstance(ctx).InstanceID()
|
||||
return &InstanceTrustedDomainsWriteModel{
|
||||
WriteModel: eventstore.WriteModel{
|
||||
AggregateID: instanceID,
|
||||
ResourceOwner: instanceID,
|
||||
InstanceID: instanceID,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (wm *InstanceTrustedDomainsWriteModel) Reduce() error {
|
||||
for _, event := range wm.Events {
|
||||
switch e := event.(type) {
|
||||
case *instance.TrustedDomainAddedEvent:
|
||||
wm.Domains = append(wm.Domains, e.Domain)
|
||||
case *instance.TrustedDomainRemovedEvent:
|
||||
wm.Domains = slices.DeleteFunc(wm.Domains, func(domain string) bool {
|
||||
return domain == e.Domain
|
||||
})
|
||||
}
|
||||
}
|
||||
return wm.WriteModel.Reduce()
|
||||
}
|
||||
|
||||
func (wm *InstanceTrustedDomainsWriteModel) Query() *eventstore.SearchQueryBuilder {
|
||||
return eventstore.NewSearchQueryBuilder(eventstore.ColumnsEvent).
|
||||
ResourceOwner(wm.ResourceOwner).
|
||||
AddQuery().
|
||||
AggregateTypes(instance.AggregateType).
|
||||
AggregateIDs(wm.AggregateID).
|
||||
EventTypes(
|
||||
instance.TrustedDomainAddedEventType,
|
||||
instance.TrustedDomainRemovedEventType,
|
||||
).
|
||||
Builder()
|
||||
}
|
Reference in New Issue
Block a user