PricedItem evolved
This commit is contained in:
@@ -16,11 +16,11 @@ type BookingConfiguration struct {
|
||||
Mode booking.BookingMode `json:"mode,omitempty" bson:"mode,omitempty"`
|
||||
}
|
||||
|
||||
type PricedResource struct {
|
||||
type PricedResource[T pricing.PricingProfileITF] struct {
|
||||
Name string `json:"name,omitempty" bson:"name,omitempty"`
|
||||
Logo string `json:"logo,omitempty" bson:"logo,omitempty"`
|
||||
InstancesRefs map[string]string `json:"instances_refs,omitempty" bson:"instances_refs,omitempty"`
|
||||
SelectedPricing pricing.PricingProfileITF `json:"selected_pricing,omitempty" bson:"selected_pricing,omitempty"`
|
||||
SelectedPricing T `json:"selected_pricing,omitempty" bson:"selected_pricing,omitempty"`
|
||||
Quantity int `json:"quantity,omitempty" bson:"quantity,omitempty"`
|
||||
BookingConfiguration *BookingConfiguration `json:"booking_configuration,omitempty" bson:"booking_configuration,omitempty"`
|
||||
Variations []*pricing.PricingVariation `json:"pricing_variations" bson:"pricing_variations"`
|
||||
@@ -31,56 +31,56 @@ type PricedResource struct {
|
||||
ResourceType tools.DataType `json:"resource_type,omitempty" bson:"resource_type,omitempty"`
|
||||
}
|
||||
|
||||
func (abs *PricedResource) GetQuantity() int {
|
||||
func (abs *PricedResource[T]) GetQuantity() int {
|
||||
return abs.Quantity
|
||||
}
|
||||
|
||||
func (abs *PricedResource) AddQuantity(amount int) {
|
||||
func (abs *PricedResource[T]) AddQuantity(amount int) {
|
||||
abs.Quantity += amount
|
||||
}
|
||||
|
||||
func (abs *PricedResource) SelectPricing() pricing.PricingProfileITF {
|
||||
func (abs *PricedResource[T]) SelectPricing() pricing.PricingProfileITF {
|
||||
return abs.SelectedPricing
|
||||
}
|
||||
|
||||
func (abs *PricedResource) GetID() string {
|
||||
func (abs *PricedResource[T]) GetID() string {
|
||||
return abs.ResourceID
|
||||
}
|
||||
|
||||
func (abs *PricedResource) GetInstanceID() string {
|
||||
func (abs *PricedResource[T]) GetInstanceID() string {
|
||||
return abs.InstanceID
|
||||
}
|
||||
|
||||
func (abs *PricedResource) GetType() tools.DataType {
|
||||
func (abs *PricedResource[T]) GetType() tools.DataType {
|
||||
return abs.ResourceType
|
||||
}
|
||||
|
||||
func (abs *PricedResource) GetCreatorID() string {
|
||||
func (abs *PricedResource[T]) GetCreatorID() string {
|
||||
return abs.CreatorID
|
||||
}
|
||||
|
||||
func (abs *PricedResource) IsPurchasable() bool {
|
||||
if abs.SelectedPricing == nil {
|
||||
func (abs *PricedResource[T]) IsPurchasable() bool {
|
||||
if any(abs.SelectedPricing) == nil {
|
||||
return false
|
||||
}
|
||||
return (abs.SelectedPricing).IsPurchasable()
|
||||
return abs.SelectedPricing.IsPurchasable()
|
||||
}
|
||||
|
||||
func (abs *PricedResource) IsBooked() bool {
|
||||
if abs.SelectedPricing == nil {
|
||||
func (abs *PricedResource[T]) IsBooked() bool {
|
||||
if any(abs.SelectedPricing) == nil {
|
||||
return false
|
||||
}
|
||||
return (abs.SelectedPricing).IsBooked()
|
||||
return abs.SelectedPricing.IsBooked()
|
||||
}
|
||||
|
||||
func (abs *PricedResource) GetLocationEnd() *time.Time {
|
||||
func (abs *PricedResource[T]) GetLocationEnd() *time.Time {
|
||||
if abs.BookingConfiguration == nil {
|
||||
return nil
|
||||
}
|
||||
return abs.BookingConfiguration.UsageEnd
|
||||
}
|
||||
|
||||
func (abs *PricedResource) GetLocationStart() *time.Time {
|
||||
func (abs *PricedResource[T]) GetLocationStart() *time.Time {
|
||||
if abs.BookingConfiguration == nil {
|
||||
now := time.Now().Add(2 * time.Minute)
|
||||
return &now
|
||||
@@ -88,34 +88,34 @@ func (abs *PricedResource) GetLocationStart() *time.Time {
|
||||
return abs.BookingConfiguration.UsageStart
|
||||
}
|
||||
|
||||
func (abs *PricedResource) SetLocationStart(start time.Time) {
|
||||
func (abs *PricedResource[T]) SetLocationStart(start time.Time) {
|
||||
if abs.BookingConfiguration == nil {
|
||||
abs.BookingConfiguration = &BookingConfiguration{}
|
||||
}
|
||||
abs.BookingConfiguration.UsageStart = &start
|
||||
}
|
||||
|
||||
func (abs *PricedResource) SetLocationEnd(end time.Time) {
|
||||
func (abs *PricedResource[T]) SetLocationEnd(end time.Time) {
|
||||
if abs.BookingConfiguration == nil {
|
||||
abs.BookingConfiguration = &BookingConfiguration{}
|
||||
}
|
||||
abs.BookingConfiguration.UsageEnd = &end
|
||||
}
|
||||
|
||||
func (abs *PricedResource) GetBookingMode() booking.BookingMode {
|
||||
func (abs *PricedResource[T]) GetBookingMode() booking.BookingMode {
|
||||
if abs.BookingConfiguration == nil {
|
||||
return booking.WHEN_POSSIBLE
|
||||
}
|
||||
return abs.BookingConfiguration.Mode
|
||||
}
|
||||
|
||||
func (abs *PricedResource) GetExplicitDurationInS() float64 {
|
||||
func (abs *PricedResource[T]) GetExplicitDurationInS() float64 {
|
||||
if abs.BookingConfiguration == nil {
|
||||
abs.BookingConfiguration = &BookingConfiguration{}
|
||||
}
|
||||
if abs.BookingConfiguration.ExplicitBookingDurationS == 0 {
|
||||
if abs.BookingConfiguration.UsageEnd == nil && abs.BookingConfiguration.UsageStart == nil {
|
||||
return (5 * time.Minute).Seconds()
|
||||
return (1 * time.Hour).Seconds()
|
||||
}
|
||||
if abs.BookingConfiguration.UsageEnd == nil {
|
||||
add := abs.BookingConfiguration.UsageStart.Add(5 * time.Minute)
|
||||
@@ -126,7 +126,7 @@ func (abs *PricedResource) GetExplicitDurationInS() float64 {
|
||||
return abs.BookingConfiguration.ExplicitBookingDurationS
|
||||
}
|
||||
|
||||
func (r *PricedResource) GetPriceHT() (float64, error) {
|
||||
func (r *PricedResource[T]) GetPriceHT() (float64, error) {
|
||||
now := time.Now()
|
||||
if r.BookingConfiguration == nil {
|
||||
r.BookingConfiguration = &BookingConfiguration{}
|
||||
@@ -138,8 +138,8 @@ func (r *PricedResource) GetPriceHT() (float64, error) {
|
||||
add := r.BookingConfiguration.UsageStart.Add(time.Duration(1 * time.Hour))
|
||||
r.BookingConfiguration.UsageEnd = &add
|
||||
}
|
||||
if r.SelectedPricing == nil {
|
||||
return 0, errors.New("pricing profile must be set on Priced Resource " + r.ResourceID)
|
||||
if any(r.SelectedPricing) == nil {
|
||||
return 0, errors.New("pricing profile must be set for resource " + r.ResourceID)
|
||||
}
|
||||
pricing := r.SelectedPricing
|
||||
return pricing.GetPriceHT(1, 0, *r.BookingConfiguration.UsageStart, *r.BookingConfiguration.UsageEnd, r.Variations)
|
||||
|
||||
Reference in New Issue
Block a user