diff --git a/models/resources/compute.go b/models/resources/compute.go index f2a6016..7f47087 100644 --- a/models/resources/compute.go +++ b/models/resources/compute.go @@ -25,6 +25,15 @@ func (d *ComputeResource) GetAccessor(request *tools.APIRequest) utils.Accessor return NewAccessor[*ComputeResource](tools.COMPUTE_RESOURCE, request, func() utils.DBObject { return &ComputeResource{} }) } +func (abs *ComputeResource) ConvertToPricedResource( + t tools.DataType, request *tools.APIRequest) pricing.PricedItemITF { + p := abs.AbstractIntanciatedResource.ConvertToPricedResource(t, request) + priced := p.(*PricedResource) + return &PricedComputeResource{ + PricedResource: *priced, + } +} + type ComputeNode struct { Name string `json:"name,omitempty" bson:"name,omitempty"` Quantity int64 `json:"quantity" bson:"quantity" default:"1"` diff --git a/models/resources/data.go b/models/resources/data.go index 67422df..0fab993 100644 --- a/models/resources/data.go +++ b/models/resources/data.go @@ -41,6 +41,15 @@ func (d *DataResource) GetAccessor(request *tools.APIRequest) utils.Accessor { return NewAccessor[*DataResource](tools.DATA_RESOURCE, request, func() utils.DBObject { return &DataResource{} }) // Create a new instance of the accessor } +func (abs *DataResource) ConvertToPricedResource( + t tools.DataType, request *tools.APIRequest) pricing.PricedItemITF { + p := abs.AbstractIntanciatedResource.ConvertToPricedResource(t, request) + priced := p.(*PricedResource) + return &PricedDataResource{ + PricedResource: *priced, + } +} + type DataResourcePartnership struct { ResourcePartnerShip[*DataResourcePricingProfile] MaxDownloadableGbAllowed float64 `json:"allowed_gb,omitempty" bson:"allowed_gb,omitempty"` diff --git a/models/resources/interfaces.go b/models/resources/interfaces.go index 286518a..5f7b1b0 100644 --- a/models/resources/interfaces.go +++ b/models/resources/interfaces.go @@ -1,36 +1,18 @@ package resources import ( - "time" - "cloud.o-forge.io/core/oc-lib/models/common/pricing" "cloud.o-forge.io/core/oc-lib/models/resources/resource_model" "cloud.o-forge.io/core/oc-lib/models/utils" "cloud.o-forge.io/core/oc-lib/tools" ) -type ShallowResourceInterface interface { - utils.DBObject - GetType() tools.DataType - GetCreatorID() string - GetPricingID() string - GetLocationStart() *time.Time - GetLocationEnd() *time.Time - GetExplicitDurationInS() float64 - SetStartUsage(start time.Time) - SetEndUsage(end time.Time) - GetPartnership(request *tools.APIRequest) ResourcePartnerITF - SetResourceModel(model *resource_model.ResourceModel) -} - type ResourceInterface interface { utils.DBObject Trim() - Transform() utils.DBObject ConvertToPricedResource(t tools.DataType, request *tools.APIRequest) pricing.PricedItemITF SetAllowedInstances(request *tools.APIRequest) SetResourceModel(model *resource_model.ResourceModel) - SetSelection(selection *int) } type ResourceInstanceITF interface { diff --git a/models/resources/resource.go b/models/resources/resource.go index 998e70f..27bbfda 100644 --- a/models/resources/resource.go +++ b/models/resources/resource.go @@ -33,17 +33,14 @@ type AbstractResource struct { SelectedInstanceIndex *int `json:"selected_instance_index,omitempty" bson:"selected_instance_index,omitempty"` // SelectedInstance is the selected instance } -func (r *AbstractResource) SetSelection(selection *int) { - r.SelectedInstanceIndex = selection -} - -func (r *AbstractResource) Transform() utils.DBObject { - return r +func (ao *AbstractResource) GetAccessor(request *tools.APIRequest) utils.Accessor { + return nil } func (r *AbstractResource) StoreDraftDefault() { r.IsDraft = true } + func (r *AbstractResource) CanUpdate(set utils.DBObject) (bool, utils.DBObject) { if r.IsDraft != set.IsDrafted() && set.IsDrafted() { return true, set // only state can be updated @@ -55,10 +52,6 @@ func (r *AbstractResource) CanDelete() bool { return r.IsDraft // only draft bookings can be deleted } -func (ao *AbstractResource) GetAccessor(request *tools.APIRequest) utils.Accessor { - return nil -} - func (abs *AbstractResource) SetResourceModel(model *resource_model.ResourceModel) { abs.ResourceModel = model } diff --git a/models/resources/resource_accessor.go b/models/resources/resource_accessor.go index 64d139a..6cf9130 100644 --- a/models/resources/resource_accessor.go +++ b/models/resources/resource_accessor.go @@ -62,7 +62,6 @@ func (dca *resourceMongoAccessor[T]) LoadOne(id string) (utils.DBObject, int, er d.(T).SetResourceModel(resources[0].(*resource_model.ResourceModel)) } d.(T).SetAllowedInstances(dca.Request) - d = d.(T).Transform() return d, 200, nil }, dca) } @@ -74,7 +73,6 @@ func (wfa *resourceMongoAccessor[T]) LoadAll(isDraft bool) ([]utils.ShallowDBObj d.(T).SetResourceModel(resources[0].(*resource_model.ResourceModel)) } d.(T).SetAllowedInstances(wfa.Request) - d = d.(T).Transform() return d }, isDraft, wfa) } @@ -87,7 +85,6 @@ func (wfa *resourceMongoAccessor[T]) Search(filters *dbs.Filters, search string, d.(T).SetResourceModel(resources[0].(*resource_model.ResourceModel)) } d.(T).SetAllowedInstances(wfa.Request) - d = d.(T).Transform() return d }, isDraft, wfa) } diff --git a/models/resources/storage.go b/models/resources/storage.go index 3a9e095..7a91bcb 100644 --- a/models/resources/storage.go +++ b/models/resources/storage.go @@ -25,10 +25,6 @@ func (d *StorageResource) GetAccessor(request *tools.APIRequest) utils.Accessor return NewAccessor[*StorageResource](tools.STORAGE_RESOURCE, request, func() utils.DBObject { return &StorageResource{} }) // Create a new instance of the accessor } -func (r *StorageResource) Transform() utils.DBObject { - return r -} - type StorageResourceInstance struct { ResourceInstance[*StorageResourcePartnership] Local bool `bson:"local" json:"local"` diff --git a/models/resources/workflow.go b/models/resources/workflow.go index 3509a70..42e6807 100644 --- a/models/resources/workflow.go +++ b/models/resources/workflow.go @@ -2,6 +2,7 @@ package resources import ( "cloud.o-forge.io/core/oc-lib/models/common/pricing" + "cloud.o-forge.io/core/oc-lib/models/utils" "cloud.o-forge.io/core/oc-lib/tools" ) @@ -19,6 +20,10 @@ type WorkflowResource struct { abstractWorkflowResource } +func (d *WorkflowResource) GetAccessor(request *tools.APIRequest) utils.Accessor { + return NewAccessor[*ComputeResource](tools.WORKFLOW_RESOURCE, request, func() utils.DBObject { return &WorkflowResource{} }) +} + func (d *WorkflowResource) Trim() { /* EMPTY */ }