Files
sendico/api/pkg/messaging/internal/notifications/notification/notification.go
Stephan D 751045fcc0
All checks were successful
ci/woodpecker/push/db Pipeline was successful
ci/woodpecker/push/fx/1 Pipeline was successful
ci/woodpecker/push/nats Pipeline was successful
ci/woodpecker/push/fx/2 Pipeline was successful
fx build fix
2025-11-09 02:57:22 +01:00

45 lines
1.2 KiB
Go

package notifications
import (
messaging "github.com/tech/sendico/pkg/messaging/envelope"
gmessaging "github.com/tech/sendico/pkg/generated/gmessaging"
"github.com/tech/sendico/pkg/model"
nm "github.com/tech/sendico/pkg/model/notification"
"github.com/tech/sendico/pkg/mservice"
"google.golang.org/protobuf/proto"
)
type NResultNotification struct {
messaging.Envelope
result *model.NotificationResult
}
func (nrn *NResultNotification) Serialize() ([]byte, error) {
msg := gmessaging.NotificationSentEvent{
UserID: nrn.result.UserID,
Channel: nrn.result.Channel,
Locale: nrn.result.Locale,
TemplateID: nrn.result.TemplateID,
Status: &gmessaging.OperationResult{
IsSuccessful: nrn.result.Result.IsSuccessful,
ErrorDescription: nrn.result.Result.Error,
},
}
data, err := proto.Marshal(&msg)
if err != nil {
return nil, err
}
return nrn.Envelope.Wrap(data)
}
func NewNRNotification() model.NotificationEvent {
return model.NewNotification(mservice.Notifications, nm.NASent)
}
func NewNResultNotification(sender string, result *model.NotificationResult) messaging.Envelope {
return &NResultNotification{
Envelope: messaging.CreateEnvelope(sender, NewNRNotification()),
result: result,
}
}