From bc3e3a61e515173e8de3b0cba47462ffd19a8127 Mon Sep 17 00:00:00 2001 From: Vernon Keenan Date: Mon, 18 Jan 2021 11:06:25 -0800 Subject: [PATCH] reflection --- app/account-helpers.go | 13 +++++++++++++ app/contact-helpers.go | 13 +++++++++++++ app/paymentmethod-helpers.go | 14 ++++++++++++++ 3 files changed, 40 insertions(+) diff --git a/app/account-helpers.go b/app/account-helpers.go index 138a11a..4074ce9 100644 --- a/app/account-helpers.go +++ b/app/account-helpers.go @@ -2,12 +2,25 @@ package app import ( "database/sql" + "reflect" "time" "code.tnxs.net/taxnexus/lib/api/crm/crm_models" "github.com/google/uuid" ) +// ReMarshalAccount converts microservice Models object to swagger +func ReMarshalAccount(p interface{}) crm_models.Account { + // reflect input and set to crm_models type + t := reflect.ValueOf(&p).Elem() + s := crm_models.Account{} + r := reflect.ValueOf(&s).Elem() + for i := 0; i < t.NumField(); i++ { + r.Field(i).Set(t.Field(i)) + } + return s +} + // UnMarshalAccount decodes swagger to a first class object func UnMarshalAccount(s *crm_models.Account) *Account { //nolint:funlen // too bad if s.ID == "" { diff --git a/app/contact-helpers.go b/app/contact-helpers.go index 96648f1..afa42f2 100644 --- a/app/contact-helpers.go +++ b/app/contact-helpers.go @@ -2,6 +2,7 @@ package app import ( "database/sql" + "reflect" "time" "code.tnxs.net/taxnexus/lib/api/crm/crm_models" @@ -77,6 +78,18 @@ func UnMarshalContact(s *crm_models.Contact) *Contact { } } +// ReMarshalContact converts microservice Models object to swagger +func ReMarshalContact(p interface{}) crm_models.Contact { + // reflect input and set to crm_models type + t := reflect.ValueOf(&p).Elem() + s := crm_models.Contact{} + r := reflect.ValueOf(&s).Elem() + for i := 0; i < t.NumField(); i++ { + r.Field(i).Set(t.Field(i)) + } + return s +} + // MarshalToSwagger encodes first class object func (obj *Contact) MarshalToSwagger() *crm_models.Contact { return &crm_models.Contact{ diff --git a/app/paymentmethod-helpers.go b/app/paymentmethod-helpers.go index 5dc007d..f920ef8 100644 --- a/app/paymentmethod-helpers.go +++ b/app/paymentmethod-helpers.go @@ -2,12 +2,26 @@ package app import ( "database/sql" + "reflect" "time" "code.tnxs.net/taxnexus/lib/api/ops/ops_models" "github.com/google/uuid" ) +// ReMarshalPaymentMethod converts microservice Models object to swagger +func ReMarshalPaymentMethod(p interface{}) ops_models.PaymentMethod { + // reflect input and set to crm_models type + t := reflect.ValueOf(&p).Elem() + s := ops_models.PaymentMethod{} + r := reflect.ValueOf(&s).Elem() + for i := 0; i < t.NumField(); i++ { + r.Field(i).Set(t.Field(i)) + } + return s +} + +// UnMarshalPaymentMethod converts swagger to first class object func UnMarshalPaymentMethod(s *ops_models.PaymentMethod) *PaymentMethod { if s.ID == "" { s.ID = uuid.New().String()