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

     1  package destination
     2  
     3  import (
     4  	"github.com/kyma-incubator/compass/components/director/internal/domain/destination/destinationcreator"
     5  	"github.com/kyma-incubator/compass/components/director/internal/model"
     6  	"github.com/kyma-incubator/compass/components/director/internal/repo"
     7  )
     8  
     9  // NewConverter creates a new destination converter
    10  func NewConverter() *converter {
    11  	return &converter{}
    12  }
    13  
    14  type converter struct{}
    15  
    16  // ToEntity converts from internal model to entity
    17  func (c *converter) ToEntity(in *model.Destination) *Entity {
    18  	if in == nil {
    19  		return nil
    20  	}
    21  
    22  	return &Entity{
    23  		ID:                    in.ID,
    24  		Name:                  in.Name,
    25  		Type:                  string(in.Type),
    26  		URL:                   in.URL,
    27  		Authentication:        string(in.Authentication),
    28  		TenantID:              in.SubaccountID,
    29  		FormationAssignmentID: repo.NewNullableString(in.FormationAssignmentID),
    30  	}
    31  }
    32  
    33  // FromEntity converts from entity to internal model
    34  func (c *converter) FromEntity(e *Entity) *model.Destination {
    35  	if e == nil {
    36  		return nil
    37  	}
    38  
    39  	return &model.Destination{
    40  		ID:                    e.ID,
    41  		Name:                  e.Name,
    42  		Type:                  destinationcreator.Type(e.Type),
    43  		URL:                   e.URL,
    44  		Authentication:        destinationcreator.AuthType(e.Authentication),
    45  		SubaccountID:          e.TenantID,
    46  		FormationAssignmentID: repo.StringPtrFromNullableString(e.FormationAssignmentID),
    47  	}
    48  }