diff --git a/models/common/size.go b/models/common/size.go index ce05984..93b0d0a 100644 --- a/models/common/size.go +++ b/models/common/size.go @@ -32,3 +32,8 @@ const ( MEMORY HARDWARE ) + +// String() - Returns the string representation of the storage type +func (t StorageType) String() string { + return [...]string{"FILE", "STREAM", "API", "DATABASE", "S3", "MEMORY", "HARDWARE"}[t] +} diff --git a/models/resources/interfaces.go b/models/resources/interfaces.go index b8c8a24..1c45020 100644 --- a/models/resources/interfaces.go +++ b/models/resources/interfaces.go @@ -26,6 +26,7 @@ type ShallowResourceInterface interface { 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) diff --git a/models/resources/resource.go b/models/resources/resource.go index 4744da0..5885f5b 100644 --- a/models/resources/resource.go +++ b/models/resources/resource.go @@ -35,6 +35,10 @@ type AbstractResource[T ResourceInstanceITF] struct { Instances []T `json:"instances,omitempty" bson:"instances,omitempty"` // Bill is the bill of the resource // Bill is the bill of the resource } +func (r *AbstractResource[T]) Transform() utils.DBObject { + return r +} + func (r *AbstractResource[T]) StoreDraftDefault() { r.IsDraft = true } diff --git a/models/resources/storage.go b/models/resources/storage.go index bb96f55..87b5da4 100644 --- a/models/resources/storage.go +++ b/models/resources/storage.go @@ -16,7 +16,8 @@ import ( */ type StorageResource struct { AbstractResource[*StorageResourceInstance] // AbstractResource contains the basic fields of an object (id, name) - Type common.StorageType `bson:"type,omitempty" json:"type,omitempty"` // Type is the type of the storage + Type common.StorageType `bson:"type,omitempty"` // Type is the type of the storage + TypeJSON string `json:"type,omitempty"` Acronym string `bson:"acronym,omitempty" json:"acronym,omitempty"` // Acronym is the acronym of the storage } @@ -24,6 +25,11 @@ 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 { + r.TypeJSON = r.Type.String() + return r +} + type StorageResourceInstance struct { ResourceInstance[*StorageResourcePartnership] Local bool `bson:"local" json:"local"`