github.com/kyma-incubator/compass/components/director@v0.0.0-20230623144113-d764f56ff805/internal/domain/formationtemplateconstraintreferences/converter.go (about) 1 package formationtemplateconstraintreferences 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 // NewConverter creates a new formationTemplate-constraint references converter 9 func NewConverter() *converter { 10 return &converter{} 11 } 12 13 type converter struct{} 14 15 // ToEntity converts from internal model to entity 16 func (c *converter) ToEntity(in *model.FormationTemplateConstraintReference) *Entity { 17 if in == nil { 18 return nil 19 } 20 21 return &Entity{ 22 ConstraintID: in.ConstraintID, 23 FormationTemplateID: in.FormationTemplateID, 24 } 25 } 26 27 // FromEntity converts from entity to internal model 28 func (c *converter) FromEntity(e *Entity) *model.FormationTemplateConstraintReference { 29 if e == nil { 30 return nil 31 } 32 33 return &model.FormationTemplateConstraintReference{ 34 ConstraintID: e.ConstraintID, 35 FormationTemplateID: e.FormationTemplateID, 36 } 37 } 38 39 // ToModel converts from graphql to internal model 40 func (c *converter) ToModel(in *graphql.ConstraintReference) *model.FormationTemplateConstraintReference { 41 if in == nil { 42 return nil 43 } 44 45 return &model.FormationTemplateConstraintReference{ 46 ConstraintID: in.ConstraintID, 47 FormationTemplateID: in.FormationTemplateID, 48 } 49 } 50 51 // ToGraphql converts from internal model to graphql 52 func (c *converter) ToGraphql(in *model.FormationTemplateConstraintReference) *graphql.ConstraintReference { 53 if in == nil { 54 return nil 55 } 56 57 return &graphql.ConstraintReference{ 58 ConstraintID: in.ConstraintID, 59 FormationTemplateID: in.FormationTemplateID, 60 } 61 }