89 lines
2.7 KiB
Go
89 lines
2.7 KiB
Go
package svc
|
|
|
|
import (
|
|
"code.30cm.net/digimon/app-cloudep-notification-service/internal/config"
|
|
cfg "code.30cm.net/digimon/app-cloudep-notification-service/pkg/config"
|
|
useD "code.30cm.net/digimon/app-cloudep-notification-service/pkg/domain/usecase"
|
|
"code.30cm.net/digimon/app-cloudep-notification-service/pkg/repository"
|
|
"code.30cm.net/digimon/app-cloudep-notification-service/pkg/usecase"
|
|
|
|
"code.30cm.net/digimon/library-go/errs"
|
|
"code.30cm.net/digimon/library-go/errs/code"
|
|
)
|
|
|
|
type ServiceContext struct {
|
|
Config config.Config
|
|
DeliveryUseCase useD.DeliveryUseCase
|
|
TemplateUseCase useD.TemplateUseCase
|
|
}
|
|
|
|
func NewServiceContext(c config.Config) *ServiceContext {
|
|
errs.Scope = code.CloudEPNotification
|
|
|
|
InitPyroScope(c)
|
|
|
|
param := usecase.DeliveryUseCaseParam{}
|
|
if c.AmazonSesSettings.Enable {
|
|
sesRepo := repository.MustAwsSesMailRepository(repository.AwsEmailDeliveryParam{
|
|
Conf: &cfg.AmazonSesSettings{
|
|
Enable: c.AmazonSesSettings.Enable,
|
|
Sort: c.AmazonSesSettings.Sort,
|
|
PoolSize: c.AmazonSesSettings.PoolSize,
|
|
Region: c.AmazonSesSettings.Region,
|
|
Sender: c.AmazonSesSettings.Sender,
|
|
Charset: c.AmazonSesSettings.Charset,
|
|
AccessKey: c.AmazonSesSettings.AccessKey,
|
|
SecretKey: c.AmazonSesSettings.SecretKey,
|
|
Token: c.AmazonSesSettings.Token,
|
|
},
|
|
})
|
|
|
|
param.EmailProviders = append(param.EmailProviders, useD.EmailProvider{
|
|
Sort: int64(c.AmazonSesSettings.Sort),
|
|
Repo: sesRepo,
|
|
})
|
|
}
|
|
|
|
if c.SMTPConfig.Enable {
|
|
smtpRepo := repository.MustSMTPUseCase(repository.SMTPMailUseCaseParam{
|
|
Conf: cfg.SMTPConfig{
|
|
Enable: c.SMTPConfig.Enable,
|
|
Sort: c.SMTPConfig.Sort,
|
|
GoroutinePoolNum: c.SMTPConfig.GoroutinePoolNum,
|
|
Host: c.SMTPConfig.Host,
|
|
Port: c.SMTPConfig.Port,
|
|
Username: c.SMTPConfig.Username,
|
|
Password: c.SMTPConfig.Password,
|
|
},
|
|
})
|
|
|
|
param.EmailProviders = append(param.EmailProviders, useD.EmailProvider{
|
|
Sort: int64(c.SMTPConfig.Sort),
|
|
Repo: smtpRepo,
|
|
})
|
|
}
|
|
|
|
if c.MitakeSMSSender.Enable {
|
|
param.SMSProviders = append(param.SMSProviders, useD.SMSProvider{
|
|
Sort: int64(c.MitakeSMSSender.Sort),
|
|
Repo: repository.MustMitakeRepository(repository.MitakeSMSDeliveryParam{
|
|
Conf: &cfg.MitakeSMSSender{
|
|
Enable: c.MitakeSMSSender.Enable,
|
|
Sort: c.MitakeSMSSender.Sort,
|
|
User: c.MitakeSMSSender.User,
|
|
Password: c.MitakeSMSSender.Password,
|
|
PoolSize: c.MitakeSMSSender.PoolSize,
|
|
},
|
|
}),
|
|
})
|
|
}
|
|
|
|
uc := usecase.MustDeliveryUseCase(param)
|
|
|
|
return &ServiceContext{
|
|
Config: c,
|
|
DeliveryUseCase: uc,
|
|
TemplateUseCase: usecase.MustTemplateUseCase(usecase.TemplateUseCaseParam{}),
|
|
}
|
|
}
|