github.com/kyma-project/kyma-environment-broker@v0.0.1/internal/storage/dbmodel/orchestration.go (about) 1 package dbmodel 2 3 import ( 4 "encoding/json" 5 "time" 6 7 "github.com/kyma-project/kyma-environment-broker/internal" 8 9 "github.com/kyma-project/kyma-environment-broker/common/orchestration" 10 ) 11 12 // OrchestrationFilter holds the filters when listing orchestrations 13 type OrchestrationFilter struct { 14 Page int 15 PageSize int 16 Types []string 17 States []string 18 } 19 20 type OrchestrationDTO struct { 21 OrchestrationID string 22 Type string 23 State string 24 Description string 25 CreatedAt time.Time 26 UpdatedAt time.Time 27 Parameters string 28 } 29 30 func NewOrchestrationDTO(o internal.Orchestration) (OrchestrationDTO, error) { 31 params, err := json.Marshal(o.Parameters) 32 if err != nil { 33 return OrchestrationDTO{}, err 34 } 35 36 dto := OrchestrationDTO{ 37 OrchestrationID: o.OrchestrationID, 38 Type: string(o.Type), 39 State: o.State, 40 CreatedAt: o.CreatedAt, 41 UpdatedAt: o.UpdatedAt, 42 Description: o.Description, 43 Parameters: string(params), 44 } 45 return dto, nil 46 } 47 48 func (o *OrchestrationDTO) ToOrchestration() (internal.Orchestration, error) { 49 var params orchestration.Parameters 50 err := json.Unmarshal([]byte(o.Parameters), ¶ms) 51 if err != nil { 52 return internal.Orchestration{}, err 53 } 54 return internal.Orchestration{ 55 OrchestrationID: o.OrchestrationID, 56 Type: orchestration.Type(o.Type), 57 State: o.State, 58 Description: o.Description, 59 CreatedAt: o.CreatedAt, 60 UpdatedAt: o.UpdatedAt, 61 Parameters: params, 62 }, nil 63 }