Skip to content

Commit

Permalink
Renamed GetSubscriptionsSlice and optimized it
Browse files Browse the repository at this point in the history
Signed-off-by: nyagamunene <[email protected]>
  • Loading branch information
nyagamunene committed Apr 12, 2024
1 parent c4a58ad commit ed11150
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions consumers/notifiers/api/endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ func TestList(t *testing.T) {
Limit: 20,
},
Total: numSubs,
Subscriptions: GetSubscriptionsSlice(subs, 5, 25),
Subscriptions: subscriptionsSlice(subs, 5, 25),
},
},
{
Expand Down Expand Up @@ -381,7 +381,7 @@ func TestList(t *testing.T) {
Limit: 20,
},
Total: 1,
Subscriptions: GetSubscriptionsSlice(subs, 10, 11),
Subscriptions: subscriptionsSlice(subs, 10, 11),
},
},
{
Expand All @@ -401,7 +401,7 @@ func TestList(t *testing.T) {
Limit: 10,
},
Total: 50,
Subscriptions: GetSubscriptionsSlice(contact2Subs, 0, 10),
Subscriptions: subscriptionsSlice(contact2Subs, 0, 10),
},
},
{
Expand Down Expand Up @@ -552,15 +552,16 @@ type page struct {
Subscriptions []subRes `json:"subscriptions,omitempty"`
}

func GetSubscriptionsSlice(subs []subRes, start, end int) []notifiers.Subscription {
var result []notifiers.Subscription
for _, sub := range subs {
result = append(result, notifiers.Subscription{
func subscriptionsSlice(subs []subRes, start, end int) []notifiers.Subscription {
var res []notifiers.Subscription
for i := start; i < end; i++ {
sub := subs[i]
res = append(res, notifiers.Subscription{
ID: sub.ID,
OwnerID: sub.OwnerID,
Contact: sub.Contact,
Topic: sub.Topic,
})
}
return result[start:end]
return res
}

0 comments on commit ed11150

Please sign in to comment.