41 lines
1.1 KiB
Go
41 lines
1.1 KiB
Go
package subscriptions
|
|
|
|
import (
|
|
"context"
|
|
"strings"
|
|
|
|
"github.com/tech/sendico/edge/callbacks/internal/model"
|
|
"github.com/tech/sendico/edge/callbacks/internal/storage"
|
|
"github.com/tech/sendico/pkg/merrors"
|
|
"go.mongodb.org/mongo-driver/v2/bson"
|
|
)
|
|
|
|
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, eventType string, organizationRef bson.ObjectID) ([]model.Endpoint, error) {
|
|
if organizationRef == bson.NilObjectID {
|
|
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.FindActive(ctx, eventType, organizationRef)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return endpoints, nil
|
|
}
|