data change for resource struct
This commit is contained in:
@@ -22,7 +22,7 @@ import (
|
||||
* it defines the resource data
|
||||
*/
|
||||
|
||||
type AbstractResource[T ResourceInstanceITF] struct {
|
||||
type AbstractResource struct {
|
||||
utils.AbstractObject // AbstractObject contains the basic fields of an object (id, name)
|
||||
Logo string `json:"logo,omitempty" bson:"logo,omitempty" validate:"required"` // Logo is the logo of the resource
|
||||
Description string `json:"description,omitempty" bson:"description,omitempty"` // Description is the description of the resource
|
||||
@@ -30,37 +30,45 @@ type AbstractResource[T ResourceInstanceITF] struct {
|
||||
Owners []utils.Owner `json:"owners,omitempty" bson:"owners,omitempty"` // Owners is the list of owners of the resource
|
||||
ResourceModel *resource_model.ResourceModel `json:"resource_model,omitempty" bson:"resource_model,omitempty"` // ResourceModel is the model of the resource
|
||||
UsageRestrictions string `bson:"usage_restrictions,omitempty" json:"usage_restrictions,omitempty"`
|
||||
SelectedInstanceIndex int `json:"selected_instance_index,omitempty" bson:"selected_instance_index,omitempty"` // SelectedInstance is the selected instance
|
||||
Instances []T `json:"instances,omitempty" bson:"instances,omitempty"` // Bill is the bill of the resource // Bill is the bill of the resource
|
||||
SelectedInstanceIndex *int `json:"selected_instance_index,omitempty" bson:"selected_instance_index,omitempty"` // SelectedInstance is the selected instance
|
||||
}
|
||||
|
||||
func (r *AbstractResource[T]) Transform() utils.DBObject {
|
||||
func (r *AbstractResource) SetSelection(selection *int) {
|
||||
r.SelectedInstanceIndex = selection
|
||||
}
|
||||
|
||||
func (r *AbstractResource) Transform() utils.DBObject {
|
||||
return r
|
||||
}
|
||||
|
||||
func (r *AbstractResource[T]) StoreDraftDefault() {
|
||||
func (r *AbstractResource) StoreDraftDefault() {
|
||||
r.IsDraft = true
|
||||
}
|
||||
func (r *AbstractResource[T]) CanUpdate(set utils.DBObject) (bool, utils.DBObject) {
|
||||
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
|
||||
}
|
||||
return r.IsDraft != set.IsDrafted() && set.IsDrafted(), set
|
||||
}
|
||||
|
||||
func (r *AbstractResource[T]) CanDelete() bool {
|
||||
func (r *AbstractResource) CanDelete() bool {
|
||||
return r.IsDraft // only draft bookings can be deleted
|
||||
}
|
||||
|
||||
func (ao *AbstractResource[T]) GetAccessor(request *tools.APIRequest) utils.Accessor {
|
||||
func (ao *AbstractResource) GetAccessor(request *tools.APIRequest) utils.Accessor {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (abs *AbstractResource[T]) SetResourceModel(model *resource_model.ResourceModel) {
|
||||
func (abs *AbstractResource) SetResourceModel(model *resource_model.ResourceModel) {
|
||||
abs.ResourceModel = model
|
||||
}
|
||||
|
||||
func (abs *AbstractResource[T]) ConvertToPricedResource(
|
||||
type AbstractIntanciatedResource[T ResourceInstanceITF] struct {
|
||||
AbstractResource // AbstractResource contains the basic fields of an object (id, name)
|
||||
Instances []T `json:"instances,omitempty" bson:"instances,omitempty"` // Bill is the bill of the resource // Bill is the bill of the resource
|
||||
}
|
||||
|
||||
func (abs *AbstractIntanciatedResource[T]) ConvertToPricedResource(
|
||||
t tools.DataType, request *tools.APIRequest) pricing.PricedItemITF {
|
||||
instances := map[string]string{}
|
||||
profiles := map[string][]pricing.PricingProfileITF{}
|
||||
@@ -79,11 +87,11 @@ func (abs *AbstractResource[T]) ConvertToPricedResource(
|
||||
}
|
||||
}
|
||||
|
||||
func (abs *AbstractResource[T]) SetAllowedInstances(request *tools.APIRequest) {
|
||||
func (abs *AbstractIntanciatedResource[T]) SetAllowedInstances(request *tools.APIRequest) {
|
||||
abs.Instances = verifyAuthAction[T](abs.Instances, request)
|
||||
}
|
||||
|
||||
func (d *AbstractResource[T]) Trim() {
|
||||
func (d *AbstractIntanciatedResource[T]) Trim() {
|
||||
if ok, _ := (&peer.Peer{AbstractObject: utils.AbstractObject{UUID: d.CreatorID}}).IsMySelf(); !ok {
|
||||
for _, instance := range d.Instances {
|
||||
instance.ClearPeerGroups()
|
||||
@@ -91,7 +99,7 @@ func (d *AbstractResource[T]) Trim() {
|
||||
}
|
||||
}
|
||||
|
||||
func (abs *AbstractResource[T]) VerifyAuth(request *tools.APIRequest) bool {
|
||||
func (abs *AbstractIntanciatedResource[T]) VerifyAuth(request *tools.APIRequest) bool {
|
||||
return len(verifyAuthAction[T](abs.Instances, request)) > 0 || abs.AbstractObject.VerifyAuth(request)
|
||||
}
|
||||
|
||||
@@ -129,7 +137,7 @@ type ResourceInstance[T ResourcePartnerITF] struct {
|
||||
Location GeoPoint `json:"location,omitempty" bson:"location,omitempty"`
|
||||
Country countries.CountryCode `json:"country,omitempty" bson:"country,omitempty"`
|
||||
AccessProtocol string `json:"access_protocol,omitempty" bson:"access_protocol,omitempty"`
|
||||
Partnerships []T `json:"partner_resource,omitempty" bson:"partner_resource,omitempty"`
|
||||
Partnerships []T `json:"partnerships,omitempty" bson:"partnerships,omitempty"`
|
||||
}
|
||||
|
||||
func (ri *ResourceInstance[T]) GetID() string {
|
||||
|
||||
Reference in New Issue
Block a user