Skip to content

Commit

Permalink
chore: move erp
Browse files Browse the repository at this point in the history
  • Loading branch information
maxwellgithinji committed Aug 5, 2021
1 parent 1ec4183 commit 6f52bc1
Show file tree
Hide file tree
Showing 22 changed files with 2,402 additions and 2,690 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import (
"firebase.google.com/go/auth"

"github.com/savannahghi/onboarding/pkg/onboarding/infrastructure/services/engagement"
erp "gitlab.slade360emr.com/go/commontools/accounting/pkg/usecases"

crmExt "github.com/savannahghi/onboarding/pkg/onboarding/infrastructure/services/crm"
"github.com/savannahghi/onboarding/pkg/onboarding/infrastructure/services/messaging"
Expand Down Expand Up @@ -145,7 +144,6 @@ func InitializeTestService(ctx context.Context) (*interactor.Interactor, error)

firestoreExtension := fb.NewFirestoreClientExtension(fsc)
fr := fb.NewFirebaseRepository(firestoreExtension, fbc)
erp := erp.NewAccounting()
engage := engagement.NewServiceEngagementImpl(engagementClient, ext)
// hubspot usecases
hubspotService := hubspot.NewHubSpotService()
Expand All @@ -158,7 +156,6 @@ func InitializeTestService(ctx context.Context) (*interactor.Interactor, error)
ps, err := pubsubmessaging.NewServicePubSubMessaging(
pubSubClient,
ext,
erp,
crmExt,
fr,
)
Expand All @@ -168,7 +165,7 @@ func InitializeTestService(ctx context.Context) (*interactor.Interactor, error)
mes := messaging.NewServiceMessagingImpl(ext)
pinExt := extension.NewPINExtensionImpl()
profile := usecases.NewProfileUseCase(fr, ext, engage, ps, crmExt)
supplier := usecases.NewSupplierUseCases(fr, profile, erp, engage, mes, ext, ps)
supplier := usecases.NewSupplierUseCases(fr, profile, engage, mes, ext, ps)
login := usecases.NewLoginUseCases(fr, profile, ext, pinExt)
survey := usecases.NewSurveyUseCases(fr, ext)
userpin := usecases.NewUserPinUseCase(fr, profile, ext, pinExt, engage)
Expand All @@ -181,7 +178,6 @@ func InitializeTestService(ctx context.Context) (*interactor.Interactor, error)
Login: login,
Survey: survey,
UserPIN: userpin,
ERP: erp,
Engagement: engage,
PubSub: ps,
CrmExt: crmExt,
Expand Down
5 changes: 0 additions & 5 deletions pkg/onboarding/infrastructure/services/pubsub/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ import (
"github.com/savannahghi/onboarding/pkg/onboarding/infrastructure/services/crm"
"github.com/savannahghi/onboarding/pkg/onboarding/repository"
"gitlab.slade360emr.com/go/commontools/crm/pkg/domain"

erp "gitlab.slade360emr.com/go/commontools/accounting/pkg/usecases"
)

const (
Expand Down Expand Up @@ -73,7 +71,6 @@ type ServicePubSub interface {
type ServicePubSubMessaging struct {
client *pubsub.Client
baseExt extension.BaseExtension
erp erp.AccountingUsecase
crm crm.ServiceCrm
repo repository.OnboardingRepository
}
Expand All @@ -82,14 +79,12 @@ type ServicePubSubMessaging struct {
func NewServicePubSubMessaging(
client *pubsub.Client,
ext extension.BaseExtension,
erp erp.AccountingUsecase,
crm crm.ServiceCrm,
repo repository.OnboardingRepository,
) (*ServicePubSubMessaging, error) {
s := &ServicePubSubMessaging{
client: client,
baseExt: ext,
erp: erp,
crm: crm,
repo: repo,
}
Expand Down
172 changes: 86 additions & 86 deletions pkg/onboarding/infrastructure/services/pubsub/subscriber.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,94 +37,94 @@ func (ps ServicePubSubMessaging) ReceivePubSubPushMessages(

ctx := r.Context()
switch topicID {
case ps.AddPubSubNamespace(common.CreateCustomerTopic):
var data dto.CustomerPubSubMessagePayload
err := json.Unmarshal(message.Message.Data, &data)
if err != nil {
ps.baseExt.WriteJSONResponse(
w,
ps.baseExt.ErrorMap(err),
http.StatusBadRequest,
)
return
}
profile, err := ps.repo.GetUserProfileByUID(
ctx,
data.UID,
false,
)
if err != nil {
ps.baseExt.WriteJSONResponse(
w,
ps.baseExt.ErrorMap(err),
http.StatusBadRequest,
)
return
}
customer, err := ps.erp.CreateCustomer(data.CustomerPayload)
if err != nil {
ps.baseExt.WriteJSONResponse(
w,
ps.baseExt.ErrorMap(err),
http.StatusBadRequest,
)
return
}
if _, err := ps.repo.UpdateCustomerProfile(
ctx,
profile.ID,
*customer,
); err != nil {
ps.baseExt.WriteJSONResponse(
w,
ps.baseExt.ErrorMap(err),
http.StatusBadRequest,
)
return
}
// case ps.AddPubSubNamespace(common.CreateCustomerTopic):
// var data dto.CustomerPubSubMessagePayload
// err := json.Unmarshal(message.Message.Data, &data)
// if err != nil {
// ps.baseExt.WriteJSONResponse(
// w,
// ps.baseExt.ErrorMap(err),
// http.StatusBadRequest,
// )
// return
// }
// profile, err := ps.repo.GetUserProfileByUID(
// ctx,
// data.UID,
// false,
// )
// if err != nil {
// ps.baseExt.WriteJSONResponse(
// w,
// ps.baseExt.ErrorMap(err),
// http.StatusBadRequest,
// )
// return
// }
// customer, err := ps.erp.CreateCustomer(data.CustomerPayload)
// if err != nil {
// ps.baseExt.WriteJSONResponse(
// w,
// ps.baseExt.ErrorMap(err),
// http.StatusBadRequest,
// )
// return
// }
// if _, err := ps.repo.UpdateCustomerProfile(
// ctx,
// profile.ID,
// *customer,
// ); err != nil {
// ps.baseExt.WriteJSONResponse(
// w,
// ps.baseExt.ErrorMap(err),
// http.StatusBadRequest,
// )
// return
// }

case ps.AddPubSubNamespace(common.CreateSupplierTopic):
var data dto.SupplierPubSubMessagePayload
err := json.Unmarshal(message.Message.Data, &data)
if err != nil {
ps.baseExt.WriteJSONResponse(
w,
ps.baseExt.ErrorMap(err),
http.StatusBadRequest,
)
return
}
profile, err := ps.repo.GetUserProfileByUID(ctx, data.UID, false)
if err != nil {
ps.baseExt.WriteJSONResponse(
w,
ps.baseExt.ErrorMap(err),
http.StatusBadRequest,
)
return
}
supplier, err := ps.erp.CreateSupplier(data.SupplierPayload)
if err != nil {
ps.baseExt.WriteJSONResponse(
w,
ps.baseExt.ErrorMap(err),
http.StatusBadRequest,
)
return
}
// case ps.AddPubSubNamespace(common.CreateSupplierTopic):
// var data dto.SupplierPubSubMessagePayload
// err := json.Unmarshal(message.Message.Data, &data)
// if err != nil {
// ps.baseExt.WriteJSONResponse(
// w,
// ps.baseExt.ErrorMap(err),
// http.StatusBadRequest,
// )
// return
// }
// profile, err := ps.repo.GetUserProfileByUID(ctx, data.UID, false)
// if err != nil {
// ps.baseExt.WriteJSONResponse(
// w,
// ps.baseExt.ErrorMap(err),
// http.StatusBadRequest,
// )
// return
// }
// supplier, err := ps.erp.CreateSupplier(data.SupplierPayload)
// if err != nil {
// ps.baseExt.WriteJSONResponse(
// w,
// ps.baseExt.ErrorMap(err),
// http.StatusBadRequest,
// )
// return
// }

if _, err := ps.repo.ActivateSupplierProfile(
ctx,
profile.ID,
*supplier,
); err != nil {
ps.baseExt.WriteJSONResponse(
w,
ps.baseExt.ErrorMap(err),
http.StatusBadRequest,
)
return
}
// if _, err := ps.repo.ActivateSupplierProfile(
// ctx,
// profile.ID,
// *supplier,
// ); err != nil {
// ps.baseExt.WriteJSONResponse(
// w,
// ps.baseExt.ErrorMap(err),
// http.StatusBadRequest,
// )
// return
// }

case ps.AddPubSubNamespace(common.CreateCRMContact):
var CRMContact domain.CRMContact
Expand Down
7 changes: 2 additions & 5 deletions pkg/onboarding/presentation/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"github.com/savannahghi/onboarding/pkg/onboarding/domain"
"github.com/savannahghi/onboarding/pkg/onboarding/infrastructure/database/fb"
"github.com/savannahghi/onboarding/pkg/onboarding/infrastructure/services/engagement"
erp "gitlab.slade360emr.com/go/commontools/accounting/pkg/usecases"
"gitlab.slade360emr.com/go/commontools/crm/pkg/infrastructure/services/hubspot"

loginservice "github.com/savannahghi/onboarding/pkg/onboarding/infrastructure/services/login_service"
Expand Down Expand Up @@ -110,7 +109,6 @@ func Router(ctx context.Context) (*mux.Router, error) {
engagementClient := utils.NewInterServiceClient(engagementService, baseExt)

// Initialize new instance of our infrastructure services
erp := erp.NewAccounting()
engage := engagement.NewServiceEngagementImpl(engagementClient, baseExt)
mes := messaging.NewServiceMessagingImpl(baseExt)
pinExt := extension.NewPINExtensionImpl()
Expand All @@ -126,7 +124,6 @@ func Router(ctx context.Context) (*mux.Router, error) {
pubSub, err := pubsubmessaging.NewServicePubSubMessaging(
pubSubClient,
baseExt,
erp,
crmExt,
repo,
)
Expand All @@ -136,7 +133,7 @@ func Router(ctx context.Context) (*mux.Router, error) {

// Initialize the usecases
profile := usecases.NewProfileUseCase(repo, baseExt, engage, pubSub, crmExt)
supplier := usecases.NewSupplierUseCases(repo, profile, erp, engage, mes, baseExt, pubSub)
supplier := usecases.NewSupplierUseCases(repo, profile, engage, mes, baseExt, pubSub)
login := usecases.NewLoginUseCases(repo, profile, baseExt, pinExt)
survey := usecases.NewSurveyUseCases(repo, baseExt)
userpin := usecases.NewUserPinUseCase(repo, profile, baseExt, pinExt, engage)
Expand All @@ -151,7 +148,7 @@ func Router(ctx context.Context) (*mux.Router, error) {

i, err := interactor.NewOnboardingInteractor(
repo, profile, su, supplier, login, survey,
userpin, erp, engage, mes, nhif, pubSub,
userpin, engage, mes, nhif, pubSub,
sms, aitUssd, agent, admin, adminSrv, crmExt,
role,
)
Expand Down

0 comments on commit 6f52bc1

Please sign in to comment.