39 lines
998 B
Go
39 lines
998 B
Go
package subscriptions
|
|
|
|
import (
|
|
"context"
|
|
"strings"
|
|
|
|
"github.com/tech/sendico/edge/callbacks/internal/storage"
|
|
"github.com/tech/sendico/pkg/merrors"
|
|
)
|
|
|
|
type service struct {
|
|
repo storage.EndpointRepo
|
|
}
|
|
|
|
// New creates endpoint resolver service.
|
|
func New(deps Dependencies) (Resolver, error) {
|
|
if deps.EndpointRepo == nil {
|
|
return nil, merrors.InvalidArgument("subscriptions: endpoint repo is required", "endpointRepo")
|
|
}
|
|
|
|
return &service{repo: deps.EndpointRepo}, nil
|
|
}
|
|
|
|
func (s *service) Resolve(ctx context.Context, clientID, eventType string) ([]storage.Endpoint, error) {
|
|
if strings.TrimSpace(clientID) == "" {
|
|
return nil, merrors.InvalidArgument("subscriptions: client id is required", "clientID")
|
|
}
|
|
if strings.TrimSpace(eventType) == "" {
|
|
return nil, merrors.InvalidArgument("subscriptions: event type is required", "eventType")
|
|
}
|
|
|
|
endpoints, err := s.repo.FindActiveByClientAndType(ctx, clientID, eventType)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return endpoints, nil
|
|
}
|