From ffaa67fb5dca28532dab321c882087dc654494c4 Mon Sep 17 00:00:00 2001 From: mr Date: Tue, 11 Feb 2025 08:30:38 +0100 Subject: [PATCH] add purchase resource in model catalog --- models/resources/priced_resource.go | 2 +- models/resources/resource.go | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/models/resources/priced_resource.go b/models/resources/priced_resource.go index 29538ba..e553be9 100644 --- a/models/resources/priced_resource.go +++ b/models/resources/priced_resource.go @@ -84,7 +84,7 @@ func (r *PricedResource) GetPrice() (float64, error) { } if r.SelectedPricing == nil { if len(r.PricingProfiles) == 0 { - return 0, errors.New("pricing profile must be set on Priced Resource" + r.ResourceID) + return 0, errors.New("pricing profile must be set on Priced Resource " + r.ResourceID) } *r.SelectedPricing = r.PricingProfiles[0] } diff --git a/models/resources/resource.go b/models/resources/resource.go index 3de9ed2..2ade037 100644 --- a/models/resources/resource.go +++ b/models/resources/resource.go @@ -169,10 +169,20 @@ type ResourcePartnerShip[T pricing.PricingProfileITF] struct { } func (ri *ResourcePartnerShip[T]) GetPricingsProfiles(peerID string, groups []string) []pricing.PricingProfileITF { + profiles := []pricing.PricingProfileITF{} if ri.PeerGroups[peerID] != nil { + for _, ri := range ri.PricingProfiles { + profiles = append(profiles, ri) + } + if slices.Contains(groups, "*") { + for _, ri := range ri.PricingProfiles { + profiles = append(profiles, ri) + } + return profiles + } for _, p := range ri.PeerGroups[peerID] { if slices.Contains(groups, p) { - profiles := []pricing.PricingProfileITF{} + for _, ri := range ri.PricingProfiles { profiles = append(profiles, ri) } @@ -180,7 +190,7 @@ func (ri *ResourcePartnerShip[T]) GetPricingsProfiles(peerID string, groups []st } } } - return []pricing.PricingProfileITF{} + return profiles } func (rp *ResourcePartnerShip[T]) GetPeerGroups() map[string][]string {