@@ -5,10 +5,11 @@ import (
55 "net/http"
66 "time"
77
8+ "github.com/tidepool-org/platform/customerio"
89 "github.com/tidepool-org/platform/mailer"
9- "github.com/tidepool-org/platform/oura/customerio"
1010 "github.com/tidepool-org/platform/oura/jotform"
1111 "github.com/tidepool-org/platform/oura/shopify"
12+ "github.com/tidepool-org/platform/user"
1213
1314 userClient "github.com/tidepool-org/platform/user/client"
1415
@@ -71,21 +72,24 @@ func (c *confirmationClientConfig) Load() error {
7172type Service struct {
7273 * serviceService.Service
7374 domain string
75+ appValidator * appvalidate.Validator
76+ authClient * Client
7477 authStore * authStoreMongo.Store
75- workStructuredStore * workStoreStructuredMongo.Store
78+ confirmationClient confirmationClient.ClientWithResponsesInterface
79+ customerIOClient * customerio.Client
7680 dataClient dataClient.Client
7781 dataSourceClient * dataSourceClient.Client
78- confirmationClient confirmationClient.ClientWithResponsesInterface
79- taskClient task.Client
80- workClient * workService.Client
81- providerFactory * providerFactory.Factory
82- authClient * Client
83- userEventsHandler events.Runner
8482 deviceCheck apple.DeviceCheck
85- appValidator * appvalidate.Validator
8683 partnerSecrets * appvalidate.PartnerSecrets
84+ providerFactory * providerFactory.Factory
85+ shopifyClient shopify.Client
86+ taskClient task.Client
8787 twiistServiceAccountAuthorizer auth.ServiceAccountAuthorizer
88+ userEventsHandler events.Runner
89+ userClient user.Client
8890 consentService consent.Service
91+ workClient * workService.Client
92+ workStructuredStore * workStoreStructuredMongo.Store
8993}
9094
9195func New () * Service {
@@ -141,6 +145,9 @@ func (s *Service) Initialize(provider application.Provider) error {
141145 if err := s .initializeAuthClient (); err != nil {
142146 return err
143147 }
148+ if err := s .initializeUserClient (); err != nil {
149+ return err
150+ }
144151 if err := s .initializeConsentService (); err != nil {
145152 return err
146153 }
@@ -159,6 +166,12 @@ func (s *Service) Initialize(provider application.Provider) error {
159166 if err := s .initializeTwiistServiceAccountAuthorizer (); err != nil {
160167 return err
161168 }
169+ if err := s .initializeCustomerIOClient (); err != nil {
170+ return err
171+ }
172+ if err := s .initializeShopifyClient (); err != nil {
173+ return err
174+ }
162175 if err := s .initializeRouter (); err != nil {
163176 return err
164177 }
@@ -260,85 +273,119 @@ func (s *Service) terminateDomain() {
260273 }
261274}
262275
263- func (s * Service ) initializeRouter () error {
264- s .Logger ().Debug ("Creating api router" )
265-
266- apiRouter , err := authServiceApi .NewRouter (s )
276+ func (s * Service ) initializeUserClient () error {
277+ s .Logger ().Debug ("Initializing user client" )
278+ var err error
279+ s .userClient , err = userClient .NewDefaultClient (userClient.Params {
280+ ConfigReporter : s .ConfigReporter (),
281+ Logger : s .Logger (),
282+ UserAgent : s .UserAgent (),
283+ })
267284 if err != nil {
268- return errors .Wrap (err , "unable to create api router " )
285+ return errors .Wrap (err , "unable to create user client " )
269286 }
287+ return nil
288+ }
270289
271- s .Logger ().Debug ("Creating v1 router" )
290+ func (s * Service ) initializeShopifyClient () error {
291+ shopifyConfig := shopify.ClientConfig {}
292+ if err := envconfig .Process ("" , & shopifyConfig ); err != nil {
293+ return errors .Wrap (err , "unable to load shopify config" )
294+ }
272295
273- v1Router , err := authServiceApiV1 .NewRouter (s )
296+ var err error
297+ s .shopifyClient , err = shopifyClient .New (context .Background (), shopifyConfig )
274298 if err != nil {
275- return errors .Wrap (err , "unable to create v1 router " )
299+ return errors .Wrap (err , "unable to create shopify client " )
276300 }
277301
278- s .Logger ().Debug ("Creating consent router" )
302+ return nil
303+ }
304+ func (s * Service ) initializeCustomerIOClient () error {
305+ customerIOConfig := customerio.Config {}
306+ if err := envconfig .Process ("" , & customerIOConfig ); err != nil {
307+ return errors .Wrap (err , "unable to load customerio config" )
308+ }
279309
280- consentV1Router , err := consentApiV1 .NewRouter (s .consentService )
310+ var err error
311+ s .customerIOClient , err = customerio .NewClient (customerIOConfig , s .Logger ())
281312 if err != nil {
282- return errors .Wrap (err , "unable to create consent router " )
313+ return errors .Wrap (err , "unable to create customerio client " )
283314 }
284315
285- s .Logger ().Debug ("Creating jotform router" )
316+ return nil
317+ }
286318
319+ func (s * Service ) createJotformRouter () (* jotformAPI.Router , error ) {
287320 jotformConfig := jotform.Config {}
288321 if err := envconfig .Process ("" , & jotformConfig ); err != nil {
289- return errors .Wrap (err , "unable to load jotform config" )
322+ return nil , errors .Wrap (err , "unable to load jotform config" )
290323 }
291324
292- customerIOConfig := customerio. Config {}
293- if err := envconfig . Process ( "" , & customerIOConfig ); err != nil {
294- return errors .Wrap (err , "unable to load customerio config " )
325+ webhookProcessor , err := jotform . NewWebhookProcessor ( jotformConfig , s . Logger (), s . consentService , s . customerIOClient , s . userClient , s . shopifyClient )
326+ if err != nil {
327+ return nil , errors .Wrap (err , "unable to create jotform webhook processor " )
295328 }
296- customerIOClient , err := customerio .NewClient (customerIOConfig , s .Logger ())
329+
330+ jotformRouter , err := jotformAPI .NewRouter (webhookProcessor )
297331 if err != nil {
298- return errors .Wrap (err , "unable to create customerio client " )
332+ return nil , errors .Wrap (err , "unable to create jotform router " )
299333 }
300334
301- s .Logger ().Debug ("Initializing user client" )
302- usrClient , err := userClient .NewDefaultClient (userClient.Params {
303- ConfigReporter : s .ConfigReporter (),
304- Logger : s .Logger (),
305- UserAgent : s .UserAgent (),
306- })
335+ return jotformRouter , nil
336+ }
337+
338+ func (s * Service ) createShopifyRouter () (* shopifyAPI.Router , error ) {
339+ fulfillmentEventProcessor , err := shopify .NewFulfillmentEventProcessor (s .Logger (), s .customerIOClient , s .shopifyClient , s .AuthServiceClient ())
307340 if err != nil {
308- return errors .Wrap (err , "unable to create user client " )
341+ return nil , errors .Wrap (err , "unable to create fulfillment event processor " )
309342 }
310343
311- shopifyConfig := shopify.ClientConfig {}
312- if err := envconfig . Process ( "" , & shopifyConfig ); err != nil {
313- return errors .Wrap (err , "unable to load shopify config " )
344+ ordersCreateEventProcessor , err := shopify .NewOrdersCreateEventProcessor ( s . Logger (), s . customerIOClient )
345+ if err != nil {
346+ return nil , errors .Wrap (err , "unable to create orders create event processor " )
314347 }
315348
316- shopifyClnt , err := shopifyClient . New ( context . Background (), shopifyConfig )
349+ shopifyRouter , err := shopifyAPI . NewRouter ( fulfillmentEventProcessor , ordersCreateEventProcessor )
317350 if err != nil {
318- return errors .Wrap (err , "unable to create shopify client " )
351+ return nil , errors .Wrap (err , "unable to create shopify router " )
319352 }
320353
321- webhookProcessor , err := jotform .NewWebhookProcessor (jotformConfig , s .Logger (), s .consentService , customerIOClient , usrClient , shopifyClnt )
354+ return shopifyRouter , nil
355+ }
356+
357+ func (s * Service ) initializeRouter () error {
358+ s .Logger ().Debug ("Creating api router" )
359+
360+ apiRouter , err := authServiceApi .NewRouter (s )
322361 if err != nil {
323- return errors .Wrap (err , "unable to create jotform webhook processor " )
362+ return errors .Wrap (err , "unable to create api router " )
324363 }
325364
326- jotformRouter , err := jotformAPI .NewRouter (webhookProcessor )
365+ s .Logger ().Debug ("Creating v1 router" )
366+
367+ v1Router , err := authServiceApiV1 .NewRouter (s )
327368 if err != nil {
328- return errors .Wrap (err , "unable to create jotform router" )
369+ return errors .Wrap (err , "unable to create v1 router" )
329370 }
330371
331- fulfillmentEventProcessor , err := shopify .NewFulfillmentEventProcessor (s .Logger (), customerIOClient , shopifyClnt , s .AuthServiceClient ())
372+ s .Logger ().Debug ("Creating consent router" )
373+
374+ consentV1Router , err := consentApiV1 .NewRouter (s .consentService )
332375 if err != nil {
333- return errors .Wrap (err , "unable to create fulfillment event processor " )
376+ return errors .Wrap (err , "unable to create consent router " )
334377 }
335378
336- ordersCreateEventProcessor , err := shopify .NewOrdersCreateEventProcessor (s .Logger (), customerIOClient )
379+ s .Logger ().Debug ("Creating jotform router" )
380+
381+ jotformRouter , err := s .createJotformRouter ()
337382 if err != nil {
338- return errors .Wrap (err , "unable to create orders create event processor " )
383+ return errors .Wrap (err , "unable to create jotform router " )
339384 }
340385
341- shopifyRouter , err := shopifyAPI .NewRouter (fulfillmentEventProcessor , ordersCreateEventProcessor )
386+ s .Logger ().Debug ("Creating shopify router" )
387+
388+ shopifyRouter , err := s .createShopifyRouter ()
342389 if err != nil {
343390 return errors .Wrap (err , "unable to create shopify router" )
344391 }
@@ -430,24 +477,14 @@ func (s *Service) initializeConsentService() error {
430477 return errors .Wrap (err , "unable to create bddp sharer" )
431478 }
432479
433- s .Logger ().Debug ("Initializing user client" )
434- usrClient , err := userClient .NewDefaultClient (userClient.Params {
435- ConfigReporter : s .ConfigReporter (),
436- Logger : s .Logger (),
437- UserAgent : s .UserAgent (),
438- })
439- if err != nil {
440- return errors .Wrap (err , "unable to create user client" )
441- }
442-
443480 s .Logger ().Debug ("Initializing mailer" )
444481 mailr , err := mailer .Client ()
445482 if err != nil {
446483 return errors .Wrap (err , "unable to create mailer" )
447484 }
448485
449486 s .Logger ().Debug ("Initializing consent mailer" )
450- consentMailer , err := consentService .NewConsentMailer (mailr , usrClient , s .Logger ())
487+ consentMailer , err := consentService .NewConsentMailer (mailr , s . userClient , s .Logger ())
451488 if err != nil {
452489 return errors .Wrap (err , "unable to create consent mailer" )
453490 }
0 commit comments