Initial cloud-services repo - gateway service + pkg modules
This commit is contained in:
46
pkg/common/subscription_package.go
Normal file
46
pkg/common/subscription_package.go
Normal file
@@ -0,0 +1,46 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"fiskerinc.com/modules/common/dbbasemodel"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
type SubscriptionPackage struct {
|
||||
ID uuid.UUID `json:"id" pg:"type:uuid,default:uuid_generate_v4()"`
|
||||
Name string `json:"name" validate:"required,max=256"`
|
||||
Features []SubscriptionFeature `json:"features,omitempty" pg:"many2many:subscription_package_to_features"`
|
||||
dbbasemodel.DBModelBase
|
||||
}
|
||||
|
||||
func (sp *SubscriptionPackage) HasFeature(featureID uuid.UUID) bool {
|
||||
for _, feature := range sp.Features {
|
||||
if feature.ID == featureID {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
func (sp *SubscriptionPackage) AddFeature(feature *SubscriptionFeature) {
|
||||
if !sp.HasFeature(feature.ID) {
|
||||
sp.Features = append(sp.Features, *feature)
|
||||
}
|
||||
}
|
||||
|
||||
func (sp *SubscriptionPackage) RemoveFeature(feature *SubscriptionFeature) {
|
||||
if sp.HasFeature(feature.ID) {
|
||||
features := make([]SubscriptionFeature, len(sp.Features)-1)
|
||||
for _, item := range sp.Features {
|
||||
if feature.ID != item.ID {
|
||||
features[len(features)] = item
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (sp *SubscriptionPackage) String() string {
|
||||
return fmt.Sprintf("SubscriptionPackage<%v>", sp.ID)
|
||||
}
|
||||
Reference in New Issue
Block a user