refactored notificatoin / tgsettle responsibility boundaries
This commit is contained in:
@@ -36,11 +36,34 @@ func (crn *ConfirmationResultNotification) Serialize() ([]byte, error) {
|
||||
return crn.Envelope.Wrap(data)
|
||||
}
|
||||
|
||||
type ConfirmationDispatchNotification struct {
|
||||
messaging.Envelope
|
||||
payload model.ConfirmationRequestDispatch
|
||||
}
|
||||
|
||||
func (cdn *ConfirmationDispatchNotification) Serialize() ([]byte, error) {
|
||||
data, err := json.Marshal(cdn.payload)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return cdn.Envelope.Wrap(data)
|
||||
}
|
||||
|
||||
func confirmationRequestEvent() model.NotificationEvent {
|
||||
return model.NewNotification(mservice.Notifications, nm.NAConfirmationRequest)
|
||||
}
|
||||
|
||||
func confirmationResultEvent(sourceService, rail string) model.NotificationEvent {
|
||||
sourceService, rail = normalizeSourceRail(sourceService, rail)
|
||||
return model.NewNotification(mservice.Verification, nm.NotificationAction(sourceService+"."+rail))
|
||||
}
|
||||
|
||||
func confirmationDispatchEvent(sourceService, rail string) model.NotificationEvent {
|
||||
sourceService, rail = normalizeSourceRail(sourceService, rail)
|
||||
return model.NewNotification(mservice.Verification, nm.NotificationAction(sourceService+"."+rail+".dispatch"))
|
||||
}
|
||||
|
||||
func normalizeSourceRail(sourceService, rail string) (string, string) {
|
||||
action := strings.TrimSpace(sourceService)
|
||||
if action == "" {
|
||||
action = "unknown"
|
||||
@@ -51,7 +74,7 @@ func confirmationResultEvent(sourceService, rail string) model.NotificationEvent
|
||||
rail = "default"
|
||||
}
|
||||
rail = strings.ToLower(rail)
|
||||
return model.NewNotification(mservice.Verification, nm.NotificationAction(action+"."+rail))
|
||||
return action, rail
|
||||
}
|
||||
|
||||
func NewConfirmationRequestEnvelope(sender string, request *model.ConfirmationRequest) messaging.Envelope {
|
||||
@@ -75,3 +98,14 @@ func NewConfirmationResultEnvelope(sender string, result *model.ConfirmationResu
|
||||
payload: payload,
|
||||
}
|
||||
}
|
||||
|
||||
func NewConfirmationDispatchEnvelope(sender string, dispatch *model.ConfirmationRequestDispatch, sourceService, rail string) messaging.Envelope {
|
||||
var payload model.ConfirmationRequestDispatch
|
||||
if dispatch != nil {
|
||||
payload = *dispatch
|
||||
}
|
||||
return &ConfirmationDispatchNotification{
|
||||
Envelope: messaging.CreateEnvelope(sender, confirmationDispatchEvent(sourceService, rail)),
|
||||
payload: payload,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user