From a12863e6190ddac723967e6b3539b37324c5009f Mon Sep 17 00:00:00 2001 From: Vernon Keenan Date: Wed, 20 Jan 2021 19:04:43 -0800 Subject: [PATCH] Lighter Objects --- app/lead.go | 28 ------------------------- rules/contact.go | 2 +- rules/lead.go | 39 ++++++++++++++++------------------ rules/new-lead.go | 53 +++++++---------------------------------------- 4 files changed, 26 insertions(+), 96 deletions(-) diff --git a/app/lead.go b/app/lead.go index c03c854..2abd32c 100644 --- a/app/lead.go +++ b/app/lead.go @@ -4,34 +4,6 @@ import ( "database/sql" ) -// LeadActivityWrapper wraps the object with workflow params -type LeadActivityWrapper struct { - APIKey string - SagaID string - SagaType string - // - Address Address - Company string - Description string - Email string - FirstName string - LastName string - MobilePhone string - Name string - Phone string - RefererURL string - Status string - TenantID string - Title string - Type string - UTMCampaign string - UTMContent string - UTMMedium string - UTMSource string - UTMTerm string - Website string -} - // Lead is a first-class object type type Lead struct { ID string diff --git a/rules/contact.go b/rules/contact.go index 69f0980..6ecf9b9 100644 --- a/rules/contact.go +++ b/rules/contact.go @@ -67,7 +67,7 @@ func StoreContactActivity(ctx workflow.Context, w app.ContactActivityWrapper) er } // NotifyContactActivity sends an email to a new lead -func NotifyContactActivity(ctx context.Context, w app.ContactActivityWrapper) error { //nolint:dupl,gocritic,lll // todo #2 need email templates +func NotifyContactActivity(ctx context.Context, w app.ContactActivityWrapper) error { //nolint:gocritic,lll // todo #2 need email templates sugar.Info("workflow.notifyContact: 📥") var buf bytes.Buffer const textBody = ` diff --git a/rules/lead.go b/rules/lead.go index 6dec12d..df0c65b 100644 --- a/rules/lead.go +++ b/rules/lead.go @@ -9,39 +9,36 @@ import ( "code.tnxs.net/taxnexus/lib/api/crm/crm_models" "code.tnxs.net/taxnexus/lib/api/workflow/workflow_client/outgoing_email_message" "code.tnxs.net/taxnexus/lib/api/workflow/workflow_models" - "code.tnxs.net/taxnexus/lib/app" httptransport "github.com/go-openapi/runtime/client" "go.temporal.io/sdk/workflow" ) +// NewLeadActivityWrapper wraps the object with workflow params +type NewLeadActivityWrapper struct { + APIKey string + SagaID string + SagaType string + // + Company string + Description string + Email string + FirstName string + LastName string + UTMSource string +} + // StoreLeadActivity posts a new lead object to datastore -func StoreLeadActivity(ctx workflow.Context, w app.LeadActivityWrapper) error { //nolint:gocritic // don't care +func StoreLeadActivity(ctx workflow.Context, w NewLeadActivityWrapper) error { //nolint:gocritic // don't care obj := &crm_models.Lead{ - Address: w.Address.MarshalToCrm(), Company: w.Company, Description: w.Description, Email: w.Email, FirstName: w.FirstName, LastName: w.LastName, - MobilePhone: w.MobilePhone, - Phone: w.Phone, - RefererURL: w.RefererURL, - Status: w.Status, - TenantID: w.TenantID, - Title: w.Title, - Type: w.Type, - UTMCampaign: w.UTMCampaign, - UTMContent: w.UTMContent, - UTMMedium: w.UTMMedium, + Name: w.FirstName + " " + w.LastName, UTMSource: w.UTMSource, - UTMTerm: w.UTMTerm, - Website: w.Website, - Name: w.Name, } postLeadParams := leads.NewPostLeadsParamsWithTimeout(postTimeout) - if obj.Name == "" { - obj.Name = obj.FirstName + " " + obj.LastName - } postLeadParams.LeadRequest = &crm_models.LeadRequest{ Data: []*crm_models.Lead{obj}, } @@ -59,7 +56,7 @@ func StoreLeadActivity(ctx workflow.Context, w app.LeadActivityWrapper) error { } // NotifyLeadActivity sends an email to a new lead -func NotifyLeadActivity(ctx context.Context, w app.LeadActivityWrapper) error { //nolint:dupl,gocritic,lll // todo #2 need email templates +func NotifyLeadActivity(ctx context.Context, w NewLeadActivityWrapper) error { //nolint:gocritic,lll // todo #2 need email templates sugar.Info("workflow.notifyLead: 📥") var buf bytes.Buffer const textBody = ` @@ -83,7 +80,7 @@ Alert! New Lead Inquiry from Taxnexus.io website. emailParams.OutgoingEmailMessageRequest = &workflow_models.OutgoingEmailMessageRequest{ Data: []*workflow_models.OutgoingEmailMessage{ { - Subject: "New lead from " + w.Name, + Subject: "New lead from " + w.FirstName + " " + w.LastName, ValidatedFromAddress: "support@taxnexus.net", ToAddress: "info@taxnexus.net", FromName: "Taxnexus Onboarding", diff --git a/rules/new-lead.go b/rules/new-lead.go index 4a1692e..c4e99d5 100644 --- a/rules/new-lead.go +++ b/rules/new-lead.go @@ -3,7 +3,6 @@ package rules import ( "time" - "code.tnxs.net/taxnexus/lib/app" "go.temporal.io/sdk/temporal" temporal_workflow "go.temporal.io/sdk/workflow" ) @@ -14,57 +13,19 @@ type NewLeadWorkflowWrapper struct { SagaID string SagaType string // - // Address crm_models.Address - Company string - Description string - Email string - FirstName string - LastName string - MobilePhone string - Name string - OwnerID string - PartnerAccountID string - Phone string - ProductID string - RefererURL string - Status string - TenantID string - Title string - Type string - UTMCampaign string - UTMContent string - UTMMedium string - UTMSource string - UTMTerm string - Website string + Company string + Description string + Email string + FirstName string + LastName string + UTMSource string } // NewLeadWorkflow is a Temporal workflow func NewLeadWorkflow(ctx temporal_workflow.Context, w NewLeadWorkflowWrapper) error { //nolint:gocritic // don't care sugar.Info("rules.NewLeadWorkflow: 📥") sugar.Debugf("rules.NewLeadWorkflow: wrapper: %v", w) - transferDetails := app.LeadActivityWrapper{ - // Address: w.Address, - Company: w.Company, - Description: w.Description, - Email: w.Email, - FirstName: w.FirstName, - LastName: w.LastName, - MobilePhone: w.MobilePhone, - Name: w.Name, - Phone: w.Phone, - RefererURL: w.RefererURL, - Status: w.Status, - TenantID: w.TenantID, - Title: w.Title, - Type: w.Type, - UTMCampaign: w.UTMCampaign, - UTMContent: w.UTMContent, - UTMMedium: w.UTMMedium, - UTMSource: w.UTMSource, - UTMTerm: w.UTMTerm, - Website: w.Website, - } + transferDetails := NewLeadActivityWrapper(w) retryPolicy := &temporal.RetryPolicy{ InitialInterval: time.Second, MaximumInterval: time.Minute,