2022-10-09 15:23:52 +02:00
|
|
|
package domain
|
|
|
|
|
|
|
|
|
|
import "gitlab.com/unboundsoftware/eventsourced/eventsourced"
|
|
|
|
|
|
2023-04-27 07:09:10 +02:00
|
|
|
type OrganizationAdded struct {
|
2023-10-27 13:44:06 +00:00
|
|
|
eventsourced.BaseEvent
|
2023-04-27 07:09:10 +02:00
|
|
|
Name string `json:"name"`
|
|
|
|
|
Initiator string `json:"initiator"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (a *OrganizationAdded) UpdateOrganization(o *Organization) {
|
|
|
|
|
o.Name = a.Name
|
|
|
|
|
o.Users = []string{a.Initiator}
|
|
|
|
|
o.CreatedBy = a.Initiator
|
|
|
|
|
o.CreatedAt = a.When()
|
|
|
|
|
o.ChangedBy = a.Initiator
|
|
|
|
|
o.ChangedAt = a.When()
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-22 18:37:07 +01:00
|
|
|
type UserAddedToOrganization struct {
|
|
|
|
|
eventsourced.BaseEvent
|
|
|
|
|
UserId string `json:"userId"`
|
|
|
|
|
Initiator string `json:"initiator"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (a *UserAddedToOrganization) UpdateOrganization(o *Organization) {
|
|
|
|
|
// Check if user is already in the organization
|
|
|
|
|
for _, user := range o.Users {
|
|
|
|
|
if user == a.UserId {
|
|
|
|
|
return // User already exists, no need to add
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
o.Users = append(o.Users, a.UserId)
|
|
|
|
|
o.ChangedBy = a.Initiator
|
|
|
|
|
o.ChangedAt = a.When()
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-27 07:09:10 +02:00
|
|
|
type APIKeyAdded struct {
|
2023-10-27 13:44:06 +00:00
|
|
|
eventsourced.BaseEvent
|
2023-04-27 07:09:10 +02:00
|
|
|
OrganizationId string `json:"organizationId"`
|
|
|
|
|
Name string `json:"name"`
|
|
|
|
|
Key string `json:"key"`
|
|
|
|
|
Refs []string `json:"refs"`
|
|
|
|
|
Read bool `json:"read"`
|
|
|
|
|
Publish bool `json:"publish"`
|
|
|
|
|
Initiator string `json:"initiator"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (a *APIKeyAdded) EnrichFromAggregate(aggregate eventsourced.Aggregate) {
|
|
|
|
|
a.OrganizationId = aggregate.Identity().String()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var _ eventsourced.EnrichableEvent = &APIKeyAdded{}
|
|
|
|
|
|
2025-11-22 18:37:07 +01:00
|
|
|
type APIKeyRemoved struct {
|
|
|
|
|
eventsourced.BaseEvent
|
|
|
|
|
KeyName string `json:"keyName"`
|
|
|
|
|
Initiator string `json:"initiator"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (a *APIKeyRemoved) UpdateOrganization(o *Organization) {
|
|
|
|
|
// Remove the API key from the organization
|
|
|
|
|
for i, key := range o.APIKeys {
|
|
|
|
|
if key.Name == a.KeyName {
|
|
|
|
|
o.APIKeys = append(o.APIKeys[:i], o.APIKeys[i+1:]...)
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
o.ChangedBy = a.Initiator
|
|
|
|
|
o.ChangedAt = a.When()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type OrganizationRemoved struct {
|
|
|
|
|
eventsourced.BaseEvent
|
|
|
|
|
Initiator string `json:"initiator"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (a *OrganizationRemoved) UpdateOrganization(o *Organization) {
|
|
|
|
|
// Mark organization as removed by clearing critical fields
|
|
|
|
|
// The aggregate will still exist in the event store, but it's logically deleted
|
|
|
|
|
o.ChangedBy = a.Initiator
|
|
|
|
|
o.ChangedAt = a.When()
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-09 15:23:52 +02:00
|
|
|
type SubGraphUpdated struct {
|
2023-10-27 13:44:06 +00:00
|
|
|
eventsourced.BaseEvent
|
2023-04-27 07:09:10 +02:00
|
|
|
OrganizationId string `json:"organizationId"`
|
|
|
|
|
Ref string `json:"ref"`
|
|
|
|
|
Service string `json:"service"`
|
|
|
|
|
Url *string `json:"url"`
|
|
|
|
|
WSUrl *string `json:"wsUrl"`
|
|
|
|
|
Sdl string `json:"sdl"`
|
|
|
|
|
Initiator string `json:"initiator"`
|
2022-10-09 15:23:52 +02:00
|
|
|
}
|