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

     1  package apptemplateversion
     2  
     3  import (
     4  	"github.com/kyma-incubator/compass/components/director/internal/model"
     5  	"github.com/kyma-incubator/compass/components/director/internal/repo"
     6  )
     7  
     8  type converter struct {
     9  }
    10  
    11  // NewConverter returns a new Converter that can later be used to make the conversions between the service and repository layer representations of a Compass ApplicationTemplateVersion.
    12  func NewConverter() *converter {
    13  	return &converter{}
    14  }
    15  
    16  // ToEntity converts the provided service-layer representation of an ApplicationTemplateVersion to the repository-layer one.
    17  func (c *converter) ToEntity(in *model.ApplicationTemplateVersion) *Entity {
    18  	if in == nil {
    19  		return nil
    20  	}
    21  
    22  	output := &Entity{
    23  		ID:                    in.ID,
    24  		Version:               in.Version,
    25  		Title:                 repo.NewNullableString(in.Title),
    26  		ReleaseDate:           repo.NewNullableString(in.ReleaseDate),
    27  		CorrelationIDs:        repo.NewNullableStringFromJSONRawMessage(in.CorrelationIDs),
    28  		CreatedAt:             in.CreatedAt,
    29  		ApplicationTemplateID: in.ApplicationTemplateID,
    30  	}
    31  
    32  	return output
    33  }
    34  
    35  // FromEntity converts the provided Entity repo-layer representation of an ApplicationTemplateVersion to the service-layer representation model.ApplicationTemplateVersion.
    36  func (c *converter) FromEntity(entity *Entity) *model.ApplicationTemplateVersion {
    37  	if entity == nil {
    38  		return nil
    39  	}
    40  
    41  	output := &model.ApplicationTemplateVersion{
    42  		ID:                    entity.ID,
    43  		Version:               entity.Version,
    44  		Title:                 repo.StringPtrFromNullableString(entity.Title),
    45  		ReleaseDate:           repo.StringPtrFromNullableString(entity.ReleaseDate),
    46  		CorrelationIDs:        repo.JSONRawMessageFromNullableString(entity.CorrelationIDs),
    47  		CreatedAt:             entity.CreatedAt,
    48  		ApplicationTemplateID: entity.ApplicationTemplateID,
    49  	}
    50  
    51  	return output
    52  }