feat: initial commit
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
package domain
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"gitlab.com/unboundsoftware/eventsourced/eventsourced"
|
||||
)
|
||||
|
||||
type UpdateSubGraph struct {
|
||||
Ref string
|
||||
Service string
|
||||
Url *string
|
||||
WSUrl *string
|
||||
Sdl string
|
||||
Initiator string
|
||||
}
|
||||
|
||||
func (u UpdateSubGraph) Validate(_ context.Context, aggregate eventsourced.Aggregate) error {
|
||||
switch a := aggregate.(type) {
|
||||
case *SubGraph:
|
||||
if strings.TrimSpace(u.Ref) == "" {
|
||||
return fmt.Errorf("ref is missing")
|
||||
}
|
||||
if strings.TrimSpace(u.Service) == "" {
|
||||
return fmt.Errorf("service is missing")
|
||||
}
|
||||
if strings.TrimSpace(u.Sdl) == "" {
|
||||
return fmt.Errorf("SDL is missing")
|
||||
}
|
||||
if (u.Url == nil || strings.TrimSpace(*u.Url) == "") && a.Url == nil {
|
||||
return fmt.Errorf("url is missing")
|
||||
}
|
||||
default:
|
||||
return fmt.Errorf("aggregate is not a SubGraph")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (u UpdateSubGraph) Event(context.Context) eventsourced.Event {
|
||||
return &SubGraphUpdated{
|
||||
Ref: u.Ref,
|
||||
Service: u.Service,
|
||||
Url: u.Url,
|
||||
WSUrl: u.WSUrl,
|
||||
Sdl: u.Sdl,
|
||||
Initiator: u.Initiator,
|
||||
}
|
||||
}
|
||||
|
||||
var _ eventsourced.Command = UpdateSubGraph{}
|
||||
Reference in New Issue
Block a user