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

     1  package ordpackage
     2  
     3  import (
     4  	"github.com/kyma-incubator/compass/components/director/internal/repo"
     5  	"github.com/kyma-incubator/compass/components/director/pkg/apperrors"
     6  
     7  	"github.com/kyma-incubator/compass/components/director/internal/model"
     8  )
     9  
    10  type converter struct {
    11  }
    12  
    13  // NewConverter missing godoc
    14  func NewConverter() *converter {
    15  	return &converter{}
    16  }
    17  
    18  // ToEntity missing godoc
    19  func (c *converter) ToEntity(in *model.Package) *Entity {
    20  	if in == nil {
    21  		return nil
    22  	}
    23  
    24  	output := &Entity{
    25  		ID:                           in.ID,
    26  		ApplicationID:                repo.NewNullableString(in.ApplicationID),
    27  		ApplicationTemplateVersionID: repo.NewNullableString(in.ApplicationTemplateVersionID),
    28  		OrdID:                        in.OrdID,
    29  		Vendor:                       repo.NewNullableString(in.Vendor),
    30  		Title:                        in.Title,
    31  		ShortDescription:             in.ShortDescription,
    32  		Description:                  in.Description,
    33  		Version:                      in.Version,
    34  		PackageLinks:                 repo.NewNullableStringFromJSONRawMessage(in.PackageLinks),
    35  		Links:                        repo.NewNullableStringFromJSONRawMessage(in.Links),
    36  		LicenseType:                  repo.NewNullableString(in.LicenseType),
    37  		SupportInfo:                  repo.NewNullableString(in.SupportInfo),
    38  		Tags:                         repo.NewNullableStringFromJSONRawMessage(in.Tags),
    39  		Countries:                    repo.NewNullableStringFromJSONRawMessage(in.Countries),
    40  		Labels:                       repo.NewNullableStringFromJSONRawMessage(in.Labels),
    41  		PolicyLevel:                  in.PolicyLevel,
    42  		CustomPolicyLevel:            repo.NewNullableString(in.CustomPolicyLevel),
    43  		PartOfProducts:               repo.NewNullableStringFromJSONRawMessage(in.PartOfProducts),
    44  		LineOfBusiness:               repo.NewNullableStringFromJSONRawMessage(in.LineOfBusiness),
    45  		Industry:                     repo.NewNullableStringFromJSONRawMessage(in.Industry),
    46  		ResourceHash:                 repo.NewNullableString(in.ResourceHash),
    47  		DocumentationLabels:          repo.NewNullableStringFromJSONRawMessage(in.DocumentationLabels),
    48  	}
    49  
    50  	return output
    51  }
    52  
    53  // FromEntity missing godoc
    54  func (c *converter) FromEntity(entity *Entity) (*model.Package, error) {
    55  	if entity == nil {
    56  		return nil, apperrors.NewInternalError("the Package entity is nil")
    57  	}
    58  
    59  	output := &model.Package{
    60  		ID:                           entity.ID,
    61  		ApplicationID:                repo.StringPtrFromNullableString(entity.ApplicationID),
    62  		ApplicationTemplateVersionID: repo.StringPtrFromNullableString(entity.ApplicationTemplateVersionID),
    63  		OrdID:                        entity.OrdID,
    64  		Vendor:                       repo.StringPtrFromNullableString(entity.Vendor),
    65  		Title:                        entity.Title,
    66  		ShortDescription:             entity.ShortDescription,
    67  		Description:                  entity.Description,
    68  		Version:                      entity.Version,
    69  		PackageLinks:                 repo.JSONRawMessageFromNullableString(entity.PackageLinks),
    70  		Links:                        repo.JSONRawMessageFromNullableString(entity.Links),
    71  		LicenseType:                  repo.StringPtrFromNullableString(entity.LicenseType),
    72  		SupportInfo:                  repo.StringPtrFromNullableString(entity.SupportInfo),
    73  		Tags:                         repo.JSONRawMessageFromNullableString(entity.Tags),
    74  		Countries:                    repo.JSONRawMessageFromNullableString(entity.Countries),
    75  		Labels:                       repo.JSONRawMessageFromNullableString(entity.Labels),
    76  		PolicyLevel:                  entity.PolicyLevel,
    77  		CustomPolicyLevel:            repo.StringPtrFromNullableString(entity.CustomPolicyLevel),
    78  		PartOfProducts:               repo.JSONRawMessageFromNullableString(entity.PartOfProducts),
    79  		LineOfBusiness:               repo.JSONRawMessageFromNullableString(entity.LineOfBusiness),
    80  		Industry:                     repo.JSONRawMessageFromNullableString(entity.Industry),
    81  		ResourceHash:                 repo.StringPtrFromNullableString(entity.ResourceHash),
    82  		DocumentationLabels:          repo.JSONRawMessageFromNullableString(entity.DocumentationLabels),
    83  	}
    84  
    85  	return output, nil
    86  }