feat: user service
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
package local
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"galaxy/user/internal/ports"
|
||||
)
|
||||
|
||||
// NoopDomainEventPublisher validates and discards auxiliary user-domain
|
||||
// events.
|
||||
type NoopDomainEventPublisher struct{}
|
||||
|
||||
// PublishProfileChanged validates event and discards it.
|
||||
func (NoopDomainEventPublisher) PublishProfileChanged(ctx context.Context, event ports.ProfileChangedEvent) error {
|
||||
return validateNoopPublish(ctx, "publish profile changed event", event.Validate)
|
||||
}
|
||||
|
||||
// PublishSettingsChanged validates event and discards it.
|
||||
func (NoopDomainEventPublisher) PublishSettingsChanged(ctx context.Context, event ports.SettingsChangedEvent) error {
|
||||
return validateNoopPublish(ctx, "publish settings changed event", event.Validate)
|
||||
}
|
||||
|
||||
// PublishEntitlementChanged validates event and discards it.
|
||||
func (NoopDomainEventPublisher) PublishEntitlementChanged(ctx context.Context, event ports.EntitlementChangedEvent) error {
|
||||
return validateNoopPublish(ctx, "publish entitlement changed event", event.Validate)
|
||||
}
|
||||
|
||||
// PublishSanctionChanged validates event and discards it.
|
||||
func (NoopDomainEventPublisher) PublishSanctionChanged(ctx context.Context, event ports.SanctionChangedEvent) error {
|
||||
return validateNoopPublish(ctx, "publish sanction changed event", event.Validate)
|
||||
}
|
||||
|
||||
// PublishLimitChanged validates event and discards it.
|
||||
func (NoopDomainEventPublisher) PublishLimitChanged(ctx context.Context, event ports.LimitChangedEvent) error {
|
||||
return validateNoopPublish(ctx, "publish limit changed event", event.Validate)
|
||||
}
|
||||
|
||||
// PublishDeclaredCountryChanged validates event and discards it.
|
||||
func (NoopDomainEventPublisher) PublishDeclaredCountryChanged(ctx context.Context, event ports.DeclaredCountryChangedEvent) error {
|
||||
return validateNoopPublish(ctx, "publish declared-country changed event", event.Validate)
|
||||
}
|
||||
|
||||
func validateNoopPublish(ctx context.Context, operation string, validate func() error) error {
|
||||
if ctx == nil {
|
||||
return fmt.Errorf("%s: nil context", operation)
|
||||
}
|
||||
if err := ctx.Err(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return validate()
|
||||
}
|
||||
|
||||
var (
|
||||
_ ports.ProfileChangedPublisher = NoopDomainEventPublisher{}
|
||||
_ ports.SettingsChangedPublisher = NoopDomainEventPublisher{}
|
||||
_ ports.EntitlementChangedPublisher = NoopDomainEventPublisher{}
|
||||
_ ports.SanctionChangedPublisher = NoopDomainEventPublisher{}
|
||||
_ ports.LimitChangedPublisher = NoopDomainEventPublisher{}
|
||||
_ ports.DeclaredCountryChangedPublisher = NoopDomainEventPublisher{}
|
||||
)
|
||||
Reference in New Issue
Block a user