github.com/kyma-incubator/compass/components/director@v0.0.0-20230623144113-d764f56ff805/internal/domain/ordvendor/converter.go (about) 1 package ordvendor 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.Vendor) *Entity { 20 if in == nil { 21 return nil 22 } 23 24 output := &Entity{ 25 ID: in.ID, 26 OrdID: in.OrdID, 27 ApplicationID: repo.NewNullableString(in.ApplicationID), 28 ApplicationTemplateVersionID: repo.NewNullableString(in.ApplicationTemplateVersionID), 29 Title: in.Title, 30 Partners: repo.NewNullableStringFromJSONRawMessage(in.Partners), 31 Tags: repo.NewNullableStringFromJSONRawMessage(in.Tags), 32 Labels: repo.NewNullableStringFromJSONRawMessage(in.Labels), 33 DocumentationLabels: repo.NewNullableStringFromJSONRawMessage(in.DocumentationLabels), 34 } 35 36 return output 37 } 38 39 // FromEntity missing godoc 40 func (c *converter) FromEntity(entity *Entity) (*model.Vendor, error) { 41 if entity == nil { 42 return nil, apperrors.NewInternalError("the Vendor entity is nil") 43 } 44 45 output := &model.Vendor{ 46 ID: entity.ID, 47 OrdID: entity.OrdID, 48 ApplicationID: repo.StringPtrFromNullableString(entity.ApplicationID), 49 ApplicationTemplateVersionID: repo.StringPtrFromNullableString(entity.ApplicationTemplateVersionID), 50 Title: entity.Title, 51 Partners: repo.JSONRawMessageFromNullableString(entity.Partners), 52 Tags: repo.JSONRawMessageFromNullableString(entity.Tags), 53 Labels: repo.JSONRawMessageFromNullableString(entity.Labels), 54 DocumentationLabels: repo.JSONRawMessageFromNullableString(entity.DocumentationLabels), 55 } 56 57 return output, nil 58 }