✨ Postman the notifier
This commit is contained in:
41
pkg/internal/grpc/postman.go
Normal file
41
pkg/internal/grpc/postman.go
Normal file
@ -0,0 +1,41 @@
|
||||
package grpc
|
||||
|
||||
import (
|
||||
"context"
|
||||
"git.solsynth.dev/hydrogen/dealer/pkg/internal/services"
|
||||
"git.solsynth.dev/hydrogen/dealer/pkg/proto"
|
||||
)
|
||||
|
||||
func (v *Server) DeliverNotification(ctx context.Context, request *proto.DeliverNotificationRequest) (*proto.DeliverResponse, error) {
|
||||
services.PublishDeliveryTask(request)
|
||||
return &proto.DeliverResponse{}, nil
|
||||
}
|
||||
|
||||
func (v *Server) DeliverNotificationBatch(ctx context.Context, request *proto.DeliverNotificationBatchRequest) (*proto.DeliverResponse, error) {
|
||||
for idx, provider := range request.GetProviders() {
|
||||
token := request.GetDeviceTokens()[idx]
|
||||
services.PublishDeliveryTask(&proto.DeliverNotificationRequest{
|
||||
Provider: provider,
|
||||
DeviceToken: token,
|
||||
Notify: request.GetNotify(),
|
||||
})
|
||||
}
|
||||
|
||||
return &proto.DeliverResponse{}, nil
|
||||
}
|
||||
|
||||
func (v *Server) DeliverEmail(ctx context.Context, request *proto.DeliverEmailRequest) (*proto.DeliverResponse, error) {
|
||||
services.PublishDeliveryTask(request)
|
||||
return &proto.DeliverResponse{}, nil
|
||||
}
|
||||
|
||||
func (v *Server) DeliverEmailBatch(ctx context.Context, request *proto.DeliverEmailBatchRequest) (*proto.DeliverResponse, error) {
|
||||
for _, to := range request.GetTo() {
|
||||
services.PublishDeliveryTask(&proto.DeliverEmailRequest{
|
||||
To: to,
|
||||
Email: request.GetEmail(),
|
||||
})
|
||||
}
|
||||
|
||||
return &proto.DeliverResponse{}, nil
|
||||
}
|
@ -16,6 +16,7 @@ import (
|
||||
type Server struct {
|
||||
proto.UnimplementedServiceDirectoryServer
|
||||
proto.UnimplementedStreamControllerServer
|
||||
proto.UnimplementedPostmanServer
|
||||
proto.UnimplementedAuthServer
|
||||
|
||||
srv *grpc.Server
|
||||
@ -29,6 +30,7 @@ func NewServer() *Server {
|
||||
proto.RegisterServiceDirectoryServer(server.srv, server)
|
||||
proto.RegisterStreamControllerServer(server.srv, server)
|
||||
proto.RegisterAuthServer(server.srv, server)
|
||||
proto.RegisterPostmanServer(server.srv, server)
|
||||
health.RegisterHealthServer(server.srv, server)
|
||||
|
||||
reflection.Register(server.srv)
|
||||
|
Reference in New Issue
Block a user