2024-04-02 14:46:05 +00:00
|
|
|
package workers
|
|
|
|
|
2024-04-07 17:54:54 +00:00
|
|
|
//
|
|
|
|
//import (
|
|
|
|
// "context"
|
|
|
|
// _ "embed"
|
|
|
|
// "go.uber.org/zap"
|
|
|
|
// "mailnotifier/internal/clients"
|
|
|
|
// "mailnotifier/internal/models"
|
|
|
|
// "mailnotifier/internal/repository"
|
|
|
|
//)
|
|
|
|
//
|
|
|
|
////go:embed mail/register.tmpl
|
|
|
|
//var register string
|
|
|
|
//
|
|
|
|
//type Welcomer struct {
|
|
|
|
// repo *repository.Repository
|
|
|
|
// mailClient *clients.MailClient
|
|
|
|
// logger *zap.Logger
|
|
|
|
// welcomeChan <-chan models.Message
|
|
|
|
//}
|
|
|
|
//
|
|
|
|
//type WelcomerDeps struct {
|
|
|
|
// Repo *repository.Repository
|
|
|
|
// MailClient *clients.MailClient
|
|
|
|
// Logger *zap.Logger
|
|
|
|
// WelcomeChan chan models.Message
|
|
|
|
//}
|
|
|
|
//
|
|
|
|
//func NewWelcomer(deps WelcomerDeps) *Welcomer {
|
|
|
|
// return &Welcomer{
|
|
|
|
// repo: deps.Repo,
|
|
|
|
// mailClient: deps.MailClient,
|
|
|
|
// logger: deps.Logger,
|
|
|
|
// welcomeChan: deps.WelcomeChan,
|
|
|
|
// }
|
|
|
|
//}
|
|
|
|
//
|
|
|
|
//func (w *Welcomer) Start(ctx context.Context) {
|
|
|
|
// for {
|
|
|
|
// select {
|
|
|
|
// case msg := <-w.welcomeChan:
|
|
|
|
// w.welcome(ctx, msg)
|
|
|
|
// case <-ctx.Done():
|
|
|
|
// return
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
//}
|
|
|
|
//
|
|
|
|
//func (w *Welcomer) welcome(ctx context.Context, msg models.Message) {
|
|
|
|
// err := w.mailClient.MailSender(clients.SenderDeps{
|
|
|
|
// Subject: "registration",
|
|
|
|
// Email: msg.Email,
|
|
|
|
// Tmpl: register,
|
|
|
|
// })
|
|
|
|
// if err != nil {
|
|
|
|
// w.logger.Error("error sending message to mailbox registration:", zap.Error(err))
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// msg.SendRegistration = true
|
|
|
|
// err = w.repo.Update(ctx, msg)
|
|
|
|
// if err != nil {
|
|
|
|
// w.logger.Error("error updating record for registration:", zap.Error(err))
|
|
|
|
// }
|
|
|
|
//}
|