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

     1  package runtimectx
     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  type converter struct{}
     9  
    10  // NewConverter missing godoc
    11  func NewConverter() *converter {
    12  	return &converter{}
    13  }
    14  
    15  // ToGraphQL missing godoc
    16  func (c *converter) ToGraphQL(in *model.RuntimeContext) *graphql.RuntimeContext {
    17  	if in == nil {
    18  		return nil
    19  	}
    20  
    21  	return &graphql.RuntimeContext{
    22  		ID:    in.ID,
    23  		Key:   in.Key,
    24  		Value: in.Value,
    25  	}
    26  }
    27  
    28  // MultipleToGraphQL missing godoc
    29  func (c *converter) MultipleToGraphQL(in []*model.RuntimeContext) []*graphql.RuntimeContext {
    30  	runtimeContexts := make([]*graphql.RuntimeContext, 0, len(in))
    31  	for _, r := range in {
    32  		if r == nil {
    33  			continue
    34  		}
    35  
    36  		runtimeContexts = append(runtimeContexts, c.ToGraphQL(r))
    37  	}
    38  
    39  	return runtimeContexts
    40  }
    41  
    42  // InputFromGraphQLWithRuntimeID converts graphql.RuntimeContextInput to model.RuntimeContextInput and populates the RuntimeID field. The resulting model.RuntimeContextInput is then used for creating RuntimeContext.
    43  func (c *converter) InputFromGraphQLWithRuntimeID(in graphql.RuntimeContextInput, runtimeID string) model.RuntimeContextInput {
    44  	convertedIn := c.InputFromGraphQL(in)
    45  	convertedIn.RuntimeID = runtimeID
    46  	return convertedIn
    47  }
    48  
    49  // InputFromGraphQL converts graphql.RuntimeContextInput to model.RuntimeContextInput. The resulting model.RuntimeContextInput is then used for updating already existing RuntimeContext.
    50  func (c *converter) InputFromGraphQL(in graphql.RuntimeContextInput) model.RuntimeContextInput {
    51  	return model.RuntimeContextInput{
    52  		Key:   in.Key,
    53  		Value: in.Value,
    54  	}
    55  }
    56  
    57  func (c *converter) ToEntity(model *model.RuntimeContext) *RuntimeContext {
    58  	return &RuntimeContext{
    59  		ID:        model.ID,
    60  		RuntimeID: model.RuntimeID,
    61  		Key:       model.Key,
    62  		Value:     model.Value,
    63  	}
    64  }
    65  
    66  func (c *converter) FromEntity(e *RuntimeContext) *model.RuntimeContext {
    67  	return &model.RuntimeContext{
    68  		ID:        e.ID,
    69  		RuntimeID: e.RuntimeID,
    70  		Key:       e.Key,
    71  		Value:     e.Value,
    72  	}
    73  }