Files
galaxy-game/backend/internal/notification/runtime_adapter.go
T
2026-05-06 10:14:55 +03:00

36 lines
986 B
Go

package notification
import (
"context"
"galaxy/backend/internal/runtime"
)
// RuntimeAdapter returns an implementation of
// `runtime.NotificationPublisher` backed by *Service. The adapter
// translates runtime's narrow `(kind, idempotency_key, payload)` shape
// into a notification.Intent and calls Submit. Recipient resolution is
// handled by Submit's catalog lookup: every kind runtime emits is
// `Admin: true`, so the recipient comes from the configured
// `BACKEND_NOTIFICATION_ADMIN_EMAIL`.
func (s *Service) RuntimeAdapter() runtime.NotificationPublisher {
return &runtimeAdapter{svc: s}
}
type runtimeAdapter struct {
svc *Service
}
func (a *runtimeAdapter) PublishRuntimeEvent(ctx context.Context, kind, idempotencyKey string, payload map[string]any) error {
if a == nil || a.svc == nil {
return nil
}
intent := Intent{
Kind: kind,
IdempotencyKey: idempotencyKey,
Payload: payload,
}
_, err := a.svc.Submit(ctx, intent)
return err
}