mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-12 09:37:45 +00:00
chore: move the go code into a subfolder
This commit is contained in:
26
apps/api/internal/repository/restrictions/aggregate.go
Normal file
26
apps/api/internal/repository/restrictions/aggregate.go
Normal file
@@ -0,0 +1,26 @@
|
||||
package restrictions
|
||||
|
||||
import (
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
)
|
||||
|
||||
const (
|
||||
AggregateType = "restrictions"
|
||||
AggregateVersion = "v1"
|
||||
)
|
||||
|
||||
type Aggregate struct {
|
||||
eventstore.Aggregate
|
||||
}
|
||||
|
||||
func NewAggregate(id, instanceId, resourceOwner string) *Aggregate {
|
||||
return &Aggregate{
|
||||
Aggregate: eventstore.Aggregate{
|
||||
Type: AggregateType,
|
||||
Version: AggregateVersion,
|
||||
ID: id,
|
||||
InstanceID: instanceId,
|
||||
ResourceOwner: resourceOwner,
|
||||
},
|
||||
}
|
||||
}
|
61
apps/api/internal/repository/restrictions/events.go
Normal file
61
apps/api/internal/repository/restrictions/events.go
Normal file
@@ -0,0 +1,61 @@
|
||||
package restrictions
|
||||
|
||||
import (
|
||||
"github.com/muhlemmer/gu"
|
||||
"golang.org/x/text/language"
|
||||
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
)
|
||||
|
||||
const (
|
||||
eventTypePrefix = eventstore.EventType("restrictions.")
|
||||
SetEventType = eventTypePrefix + "set"
|
||||
)
|
||||
|
||||
// SetEvent describes that restrictions are added or modified and contains only changed properties
|
||||
type SetEvent struct {
|
||||
*eventstore.BaseEvent `json:"-"`
|
||||
DisallowPublicOrgRegistration *bool `json:"disallowPublicOrgRegistration,omitempty"`
|
||||
AllowedLanguages *[]language.Tag `json:"allowedLanguages,omitempty"`
|
||||
}
|
||||
|
||||
func (e *SetEvent) Payload() any {
|
||||
return e
|
||||
}
|
||||
|
||||
func (e *SetEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (e *SetEvent) SetBaseEvent(b *eventstore.BaseEvent) {
|
||||
e.BaseEvent = b
|
||||
}
|
||||
|
||||
func NewSetEvent(
|
||||
base *eventstore.BaseEvent,
|
||||
changes ...RestrictionsChange,
|
||||
) *SetEvent {
|
||||
changedEvent := &SetEvent{
|
||||
BaseEvent: base,
|
||||
}
|
||||
for _, change := range changes {
|
||||
change(changedEvent)
|
||||
}
|
||||
return changedEvent
|
||||
}
|
||||
|
||||
type RestrictionsChange func(*SetEvent)
|
||||
|
||||
func ChangeDisallowPublicOrgRegistration(disallow bool) RestrictionsChange {
|
||||
return func(e *SetEvent) {
|
||||
e.DisallowPublicOrgRegistration = gu.Ptr(disallow)
|
||||
}
|
||||
}
|
||||
|
||||
func ChangeAllowedLanguages(allowedLanguages []language.Tag) RestrictionsChange {
|
||||
return func(e *SetEvent) {
|
||||
e.AllowedLanguages = &allowedLanguages
|
||||
}
|
||||
}
|
||||
|
||||
var SetEventMapper = eventstore.GenericEventMapper[SetEvent]
|
9
apps/api/internal/repository/restrictions/eventstore.go
Normal file
9
apps/api/internal/repository/restrictions/eventstore.go
Normal file
@@ -0,0 +1,9 @@
|
||||
package restrictions
|
||||
|
||||
import (
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
)
|
||||
|
||||
func init() {
|
||||
eventstore.RegisterFilterEventMapper(AggregateType, SetEventType, SetEventMapper)
|
||||
}
|
Reference in New Issue
Block a user