From ecc50afda26b1aa6e591b920bd303cb8631ebc91 Mon Sep 17 00:00:00 2001 From: Sarah Roberts Date: Fri, 1 Nov 2024 12:09:15 -0700 Subject: [PATCH] CORE-2016: reimplemented GetDefaultQuotaValue in terms of GetDefaultQuotaValues for added clarity --- internal/model/plan.go | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/internal/model/plan.go b/internal/model/plan.go index a23d69a..d90314a 100644 --- a/internal/model/plan.go +++ b/internal/model/plan.go @@ -53,25 +53,18 @@ func (p *Plan) GetActivePlanRate() (*PlanRate, error) { } // GetDefaultQuotaValue returns the default quota value associated with the resource type with the given name. This -// funciton assumes that the plan quota defaults ar sorted in ascending order by effective date. -func (p *Plan) GetDefaultQuotaValue(resourcetypeName string) float64 { - currentTime := time.Now() +// function assumes that the plan quota defaults are sorted in ascending order by effective date. +func (p *Plan) GetDefaultQuotaValue(resourceTypeName string) float64 { // Find the active plan quota default value for the given resource type. - var value float64 - for _, quotaDefault := range p.PlanQuotaDefaults { - if quotaDefault.EffectiveDate.After(currentTime) { - break - } - if quotaDefault.ResourceType.Name == resourcetypeName { - value = quotaDefault.QuotaValue - } + pqd := p.GetDefaultQuotaValues()[resourceTypeName] + if pqd == nil { + return 0 } - - return value + return pqd.QuotaValue } -// GetActiveQuotaValues returns the active quota values for a plan. This function assumes that the plan quota defaults +// GetDefaultQuotaValues returns the active quota values for a plan. This function assumes that the plan quota defaults // are sorted in ascending order by effective date. func (p *Plan) GetDefaultQuotaValues() map[string]*PlanQuotaDefault { currentTime := time.Now()