Skip to content

Commit

Permalink
[dss/RIDv2] group subscriptions to notify by their callback URL (#1105)
Browse files Browse the repository at this point in the history
  • Loading branch information
Shastick authored Sep 9, 2024
1 parent ae62756 commit 2294186
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 12 deletions.
24 changes: 24 additions & 0 deletions pkg/rid/models/api/v2/conversions.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,30 @@ func ToSubscriberToNotify(s *ridmodels.Subscription) *restapi.SubscriberToNotify
}
}

// MakeSubscribersToNotify groups the passed subscriptions by their callback URL,
// returning a collection of subscribers to notify that contains one entry per distinct callback URL.
func MakeSubscribersToNotify(subscriptions []*ridmodels.Subscription) []restapi.SubscriberToNotify {
subscriptionsByURL := map[string][]restapi.SubscriptionState{}
for _, sub := range subscriptions {
notifIdx := restapi.SubscriptionNotificationIndex(sub.NotificationIndex)
subState := restapi.SubscriptionState{
SubscriptionId: restapi.SubscriptionUUID(sub.ID),
NotificationIndex: &notifIdx,
}
subscriptionsByURL[sub.URL] = append(subscriptionsByURL[sub.URL], subState)
}

result := []restapi.SubscriberToNotify{}
for url, states := range subscriptionsByURL {
result = append(result, restapi.SubscriberToNotify{
Url: restapi.URL(url),
Subscriptions: states,
})
}

return result
}

// ToSubscription converts a subscription business object to a Subscription
// RID v2 REST model for API consumption.
func ToSubscription(s *ridmodels.Subscription) *restapi.Subscription {
Expand Down
15 changes: 3 additions & 12 deletions pkg/rid/server/v2/isa_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,7 @@ func (s *Server) CreateIdentificationServiceArea(ctx context.Context, req *resta
}
}

apiSubscribers := make([]restapi.SubscriberToNotify, 0, len(subscribers))
for _, subscriber := range subscribers {
apiSubscribers = append(apiSubscribers, *apiv2.ToSubscriberToNotify(subscriber))
}
apiSubscribers := apiv2.MakeSubscribersToNotify(subscribers)

return restapi.CreateIdentificationServiceAreaResponseSet{Response200: &restapi.PutIdentificationServiceAreaResponse{
ServiceArea: *apiv2.ToIdentificationServiceArea(insertedISA),
Expand Down Expand Up @@ -199,10 +196,7 @@ func (s *Server) UpdateIdentificationServiceArea(ctx context.Context, req *resta
}
}

apiSubscribers := make([]restapi.SubscriberToNotify, 0, len(subscribers))
for _, subscriber := range subscribers {
apiSubscribers = append(apiSubscribers, *apiv2.ToSubscriberToNotify(subscriber))
}
apiSubscribers := apiv2.MakeSubscribersToNotify(subscribers)

return restapi.UpdateIdentificationServiceAreaResponseSet{Response200: &restapi.PutIdentificationServiceAreaResponse{
ServiceArea: *apiv2.ToIdentificationServiceArea(insertedISA),
Expand Down Expand Up @@ -253,10 +247,7 @@ func (s *Server) DeleteIdentificationServiceArea(ctx context.Context, req *resta
}
}

apiSubscribers := make([]restapi.SubscriberToNotify, 0, len(subscribers))
for _, subscriber := range subscribers {
apiSubscribers = append(apiSubscribers, *apiv2.ToSubscriberToNotify(subscriber))
}
apiSubscribers := apiv2.MakeSubscribersToNotify(subscribers)

return restapi.DeleteIdentificationServiceAreaResponseSet{Response200: &restapi.DeleteIdentificationServiceAreaResponse{
ServiceArea: *apiv2.ToIdentificationServiceArea(isa),
Expand Down

0 comments on commit 2294186

Please sign in to comment.