From e55727d9e2732b1fb4f7cbb118779d274ac4d48e Mon Sep 17 00:00:00 2001 From: mr Date: Mon, 10 Feb 2025 10:42:37 +0100 Subject: [PATCH] add purchase resource in model catalog --- models/resources/compute.go | 2 ++ models/resources/priced_resource.go | 6 +++++- models/resources/storage.go | 2 ++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/models/resources/compute.go b/models/resources/compute.go index 0601ab8..3042637 100644 --- a/models/resources/compute.go +++ b/models/resources/compute.go @@ -2,6 +2,7 @@ package resources import ( "errors" + "fmt" "strings" "time" @@ -138,6 +139,7 @@ func (r *PricedComputeResource) GetType() tools.DataType { } func (r *PricedComputeResource) 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") } diff --git a/models/resources/priced_resource.go b/models/resources/priced_resource.go index 59ec77f..047766f 100644 --- a/models/resources/priced_resource.go +++ b/models/resources/priced_resource.go @@ -71,9 +71,13 @@ func (abs *PricedResource) SetLocationEnd(end time.Time) { func (abs *PricedResource) GetExplicitDurationInS() float64 { if abs.ExplicitBookingDurationS == 0 { - if abs.UsageEnd == nil || abs.UsageStart == nil { + if abs.UsageEnd == nil && abs.UsageStart == nil { return time.Duration(1 * time.Hour).Seconds() } + if abs.UsageEnd == nil { + add := abs.UsageStart.Add(time.Duration(1 * time.Hour)) + abs.UsageEnd = &add + } return abs.UsageEnd.Sub(*abs.UsageStart).Seconds() } return abs.ExplicitBookingDurationS diff --git a/models/resources/storage.go b/models/resources/storage.go index dfd1cc8..3ecac88 100644 --- a/models/resources/storage.go +++ b/models/resources/storage.go @@ -2,6 +2,7 @@ package resources import ( "errors" + "fmt" "time" "cloud.o-forge.io/core/oc-lib/models/common/enum" @@ -161,6 +162,7 @@ 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") }