github.com/kyma-incubator/compass/components/director@v0.0.0-20230623144113-d764f56ff805/internal/domain/scenarioassignment/converter.go (about)

     1  package scenarioassignment
     2  
     3  import (
     4  	"github.com/kyma-incubator/compass/components/director/internal/model"
     5  	"github.com/kyma-incubator/compass/components/director/pkg/graphql"
     6  )
     7  
     8  // SubaccountIDKey is the key used for the subaccount_id label
     9  const SubaccountIDKey = "global_subaccount_id"
    10  
    11  // NewConverter creates a new instance of gqlConverter
    12  func NewConverter() *converter {
    13  	return &converter{}
    14  }
    15  
    16  type converter struct{}
    17  
    18  // ToGraphQL converts from internal model to GraphQL output
    19  func (c *converter) ToGraphQL(in model.AutomaticScenarioAssignment, targetTenantExternalID string) graphql.AutomaticScenarioAssignment {
    20  	return graphql.AutomaticScenarioAssignment{
    21  		ScenarioName: in.ScenarioName,
    22  		Selector: &graphql.Label{
    23  			Key:   SubaccountIDKey,
    24  			Value: targetTenantExternalID,
    25  		},
    26  	}
    27  }
    28  
    29  // ToEntity converts from internal model to entity
    30  func (c *converter) ToEntity(in model.AutomaticScenarioAssignment) Entity {
    31  	return Entity{
    32  		TenantID:       in.Tenant,
    33  		Scenario:       in.ScenarioName,
    34  		TargetTenantID: in.TargetTenantID,
    35  	}
    36  }
    37  
    38  // FromEntity converts from entity to internal model
    39  func (c *converter) FromEntity(in Entity) model.AutomaticScenarioAssignment {
    40  	return model.AutomaticScenarioAssignment{
    41  		ScenarioName:   in.Scenario,
    42  		Tenant:         in.TenantID,
    43  		TargetTenantID: in.TargetTenantID,
    44  	}
    45  }