add purchase resource in model catalog

This commit is contained in:
mr
2025-02-10 13:04:13 +01:00
parent f663ec80f5
commit 4ad32401fd
4 changed files with 51 additions and 29 deletions

View File

@@ -163,13 +163,21 @@ func (r *PricedStorageResource) GetType() tools.DataType {
func (r *PricedStorageResource) GetPrice() (float64, error) {
fmt.Println("GetPrice", r.UsageStart, r.UsageEnd)
if r.UsageStart == nil || r.UsageEnd == nil {
return 0, errors.New("usage start and end must be set")
now := time.Now()
if r.UsageStart == nil {
r.UsageStart = &now
}
if r.SelectedPricing == nil {
return 0, errors.New("selected pricing must be set")
if r.UsageEnd == nil {
add := r.UsageStart.Add(time.Duration(1 * time.Hour))
r.UsageEnd = &add
}
pricing := *r.SelectedPricing
if pricing == nil {
if len(r.PricingProfiles) == 0 {
return 0, errors.New("pricing profile must be set")
}
pricing = r.PricingProfiles[0]
}
var err error
amountOfData := float64(1)
if pricing.GetOverrideStrategyValue() >= 0 {