From 8e4ebbf6225a53bc223cbef1ade61d5e0d7a0aa1 Mon Sep 17 00:00:00 2001 From: mr Date: Mon, 20 Jan 2025 13:26:30 +0100 Subject: [PATCH] light modification --- models/resources/compute.go | 4 ++++ models/resources/data.go | 4 ++++ models/resources/processing.go | 4 ++++ models/resources/resource.go | 5 +++++ models/resources/storage.go | 4 ++++ models/resources/workflow.go | 4 ++++ models/utils/abstracts.go | 10 +++++----- 7 files changed, 30 insertions(+), 5 deletions(-) diff --git a/models/resources/compute.go b/models/resources/compute.go index e2032ff..0601ab8 100644 --- a/models/resources/compute.go +++ b/models/resources/compute.go @@ -26,6 +26,10 @@ func (d *ComputeResource) GetAccessor(request *tools.APIRequest) utils.Accessor return NewAccessor[*ComputeResource](tools.COMPUTE_RESOURCE, request, func() utils.DBObject { return &ComputeResource{} }) } +func (r *ComputeResource) GetType() string { + return tools.COMPUTE_RESOURCE.String() +} + func (abs *ComputeResource) ConvertToPricedResource( t tools.DataType, request *tools.APIRequest) pricing.PricedItemITF { if t != tools.COMPUTE_RESOURCE { diff --git a/models/resources/data.go b/models/resources/data.go index cdde900..ed5d761 100644 --- a/models/resources/data.go +++ b/models/resources/data.go @@ -32,6 +32,10 @@ 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 (r *DataResource) GetType() string { + return tools.DATA_RESOURCE.String() +} + func (abs *DataResource) ConvertToPricedResource( t tools.DataType, request *tools.APIRequest) pricing.PricedItemITF { if t != tools.DATA_RESOURCE { diff --git a/models/resources/processing.go b/models/resources/processing.go index 829cc5f..3885484 100644 --- a/models/resources/processing.go +++ b/models/resources/processing.go @@ -35,6 +35,10 @@ type ProcessingResource struct { Container *models.Container `json:"container,omitempty" bson:"container,omitempty"` // Container is the container } +func (r *ProcessingResource) GetType() string { + return tools.PROCESSING_RESOURCE.String() +} + type PricedProcessingResource struct { PricedResource IsService bool diff --git a/models/resources/resource.go b/models/resources/resource.go index 35a3425..bb9c7f3 100644 --- a/models/resources/resource.go +++ b/models/resources/resource.go @@ -33,6 +33,10 @@ type AbstractResource struct { SelectedInstanceIndex *int `json:"selected_instance_index,omitempty" bson:"selected_instance_index,omitempty"` // SelectedInstance is the selected instance } +func (r *AbstractResource) GetType() string { + return r.Type +} + func (r *AbstractResource) StoreDraftDefault() { r.IsDraft = true } @@ -81,6 +85,7 @@ func (abs *AbstractIntanciatedResource[T]) SetAllowedInstances(request *tools.AP } func (d *AbstractIntanciatedResource[T]) Trim() { + d.AbstractResource.AbstractObject.Type = d.GetType() if ok, _ := (&peer.Peer{AbstractObject: utils.AbstractObject{UUID: d.CreatorID}}).IsMySelf(); !ok { for _, instance := range d.Instances { instance.ClearPeerGroups() diff --git a/models/resources/storage.go b/models/resources/storage.go index 1041956..38ac6e8 100644 --- a/models/resources/storage.go +++ b/models/resources/storage.go @@ -24,6 +24,10 @@ 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) GetType() string { + return tools.STORAGE_RESOURCE.String() +} + func (abs *StorageResource) ConvertToPricedResource( t tools.DataType, request *tools.APIRequest) pricing.PricedItemITF { if t != tools.STORAGE_RESOURCE { diff --git a/models/resources/workflow.go b/models/resources/workflow.go index 7c97223..7ffda78 100644 --- a/models/resources/workflow.go +++ b/models/resources/workflow.go @@ -19,6 +19,10 @@ func (d *WorkflowResource) GetAccessor(request *tools.APIRequest) utils.Accessor return NewAccessor[*ComputeResource](tools.WORKFLOW_RESOURCE, request, func() utils.DBObject { return &WorkflowResource{} }) } +func (r *WorkflowResource) GetType() string { + return tools.WORKFLOW_RESOURCE.String() +} + func (d *WorkflowResource) Trim() { /* EMPTY */ } diff --git a/models/utils/abstracts.go b/models/utils/abstracts.go index 8617f30..10088f8 100644 --- a/models/utils/abstracts.go +++ b/models/utils/abstracts.go @@ -27,11 +27,11 @@ const ( * every data in base root model should inherit from this struct (only exception is the ResourceModel) */ type AbstractObject struct { - UUID string `json:"id,omitempty" bson:"id,omitempty" validate:"required"` - Name string `json:"name,omitempty" bson:"name,omitempty" validate:"required"` - IsDraft bool `json:"is_draft" bson:"is_draft" default:"false"` - CreatorID string `json:"creator_id" bson:"creator_id" default:"unknown"` - + UUID string `json:"id,omitempty" bson:"id,omitempty" validate:"required"` + Name string `json:"name,omitempty" bson:"name,omitempty" validate:"required"` + IsDraft bool `json:"is_draft" bson:"is_draft" default:"false"` + CreatorID string `json:"creator_id" bson:"creator_id" default:"unknown"` + Type string `json:"type,omitempty" bson:"type,omitempty"` CreationDate time.Time `json:"creation_date" bson:"creation_date"` UpdateDate time.Time `json:"update_date" bson:"update_date"` UpdaterID string `json:"updater_id" bson:"updater_id"`