PricedItem evolved
This commit is contained in:
@@ -73,9 +73,9 @@ func (abs *AbstractInstanciatedResource[T]) AddInstances(instance ResourceInstan
|
||||
abs.Instances = append(abs.Instances, instance.(T))
|
||||
}
|
||||
|
||||
func (abs *AbstractInstanciatedResource[T]) ConvertToPricedResource(t tools.DataType,
|
||||
func ConvertToPricedResource[T pricing.PricingProfileITF](t tools.DataType,
|
||||
selectedInstance *int, selectedPartnership *int, selectedBuyingStrategy *int, selectedStrategy *int,
|
||||
selectedBookingModeIndex *int, request *tools.APIRequest) (pricing.PricedItemITF, error) {
|
||||
selectedBookingModeIndex *int, abs ResourceInterface, request *tools.APIRequest) (pricing.PricedItemITF, error) {
|
||||
instances := map[string]string{}
|
||||
var profile pricing.PricingProfileITF
|
||||
var inst ResourceInstanceITF
|
||||
@@ -84,7 +84,7 @@ func (abs *AbstractInstanciatedResource[T]) ConvertToPricedResource(t tools.Data
|
||||
instances[t.GetID()] = t.GetName()
|
||||
profile = t.GetProfile(request.PeerID, selectedPartnership, selectedBuyingStrategy, selectedStrategy)
|
||||
} else {
|
||||
for i, instance := range abs.Instances { // TODO why it crush before ?
|
||||
for i, instance := range abs.SetAllowedInstances(request) { // TODO why it crush before ?
|
||||
if i == 0 {
|
||||
inst = instance
|
||||
}
|
||||
@@ -106,8 +106,8 @@ func (abs *AbstractInstanciatedResource[T]) ConvertToPricedResource(t tools.Data
|
||||
}*/
|
||||
}
|
||||
variations := []*pricing.PricingVariation{}
|
||||
if selectedBookingModeIndex != nil && abs.AllowedBookingModes[booking.BookingMode(*selectedBookingModeIndex)] != nil {
|
||||
variations = append(variations, abs.AllowedBookingModes[booking.BookingMode(*selectedBookingModeIndex)])
|
||||
if selectedBookingModeIndex != nil && abs.GetBookingModes()[booking.BookingMode(*selectedBookingModeIndex)] != nil {
|
||||
variations = append(variations, abs.GetBookingModes()[booking.BookingMode(*selectedBookingModeIndex)])
|
||||
}
|
||||
// Seed the booking configuration with the instance's historical average duration
|
||||
// so GetExplicitDurationInS() returns a realistic default out of the box.
|
||||
@@ -117,17 +117,21 @@ func (abs *AbstractInstanciatedResource[T]) ConvertToPricedResource(t tools.Data
|
||||
bc = &BookingConfiguration{ExplicitBookingDurationS: avg}
|
||||
}
|
||||
}
|
||||
return &PricedResource{
|
||||
Name: abs.Name,
|
||||
Logo: abs.Logo,
|
||||
ResourceID: abs.UUID,
|
||||
InstanceID: inst.GetID(),
|
||||
instanceID := ""
|
||||
if inst != nil {
|
||||
instanceID = inst.GetID()
|
||||
}
|
||||
selectedPricing, _ := profile.(T)
|
||||
return &PricedResource[T]{
|
||||
Name: abs.GetName(),
|
||||
ResourceID: abs.GetID(),
|
||||
InstanceID: instanceID,
|
||||
ResourceType: t,
|
||||
Quantity: 1,
|
||||
InstancesRefs: instances,
|
||||
SelectedPricing: profile,
|
||||
SelectedPricing: selectedPricing,
|
||||
Variations: variations,
|
||||
CreatorID: abs.CreatorID,
|
||||
CreatorID: abs.GetCreatorID(),
|
||||
BookingConfiguration: bc,
|
||||
}, nil
|
||||
}
|
||||
@@ -149,11 +153,16 @@ func (r *AbstractInstanciatedResource[T]) GetSelectedInstance(selected *int) Res
|
||||
return nil
|
||||
}
|
||||
|
||||
func (abs *AbstractInstanciatedResource[T]) SetAllowedInstances(request *tools.APIRequest, instanceID ...string) {
|
||||
if (request != nil && request.PeerID == abs.CreatorID && request.PeerID != "") || request.Admin {
|
||||
return
|
||||
func (abs *AbstractInstanciatedResource[T]) SetAllowedInstances(request *tools.APIRequest, instanceID ...string) []ResourceInstanceITF {
|
||||
if !((request != nil && request.PeerID == abs.CreatorID && request.PeerID != "") || request.Admin) {
|
||||
abs.Instances = VerifyAuthAction(abs.Instances, request, instanceID...)
|
||||
}
|
||||
abs.Instances = VerifyAuthAction(abs.Instances, request, instanceID...)
|
||||
inst := []ResourceInstanceITF{}
|
||||
for _, i := range abs.Instances {
|
||||
inst = append(inst, i)
|
||||
}
|
||||
|
||||
return inst
|
||||
}
|
||||
|
||||
func (abs *AbstractInstanciatedResource[T]) VerifyAuth(callName string, request *tools.APIRequest) bool {
|
||||
|
||||
Reference in New Issue
Block a user