aboutsummaryrefslogtreecommitdiffstats
path: root/internal/notifier
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--internal/notifier/notifier.go17
-rw-r--r--internal/notifier/notifiers.go15
-rw-r--r--internal/notifier/scheduler.go5
-rw-r--r--internal/notifier/telegram/telegram.go2
4 files changed, 35 insertions, 4 deletions
diff --git a/internal/notifier/notifier.go b/internal/notifier/notifier.go
new file mode 100644
index 0000000..7ce94b0
--- /dev/null
+++ b/internal/notifier/notifier.go
@@ -0,0 +1,17 @@
+package notifier
+
+import (
+ "context"
+
+ chModel "donetick.com/core/internal/chore/model"
+ nModel "donetick.com/core/internal/notifier/model"
+ uModel "donetick.com/core/internal/user/model"
+)
+
+type Notifier interface {
+ SendChoreReminder(c context.Context, chore *chModel.Chore, users []*uModel.User)
+ SendChoreCompletion(c context.Context, chore *chModel.Chore, user *uModel.User)
+ SendChoreOverdue(c context.Context, chore *chModel.Chore, users []*uModel.User)
+ SendChorePreDue(c context.Context, chore *chModel.Chore, users []*uModel.User)
+ SendNotification(c context.Context, notification *nModel.Notification)
+}
diff --git a/internal/notifier/notifiers.go b/internal/notifier/notifiers.go
new file mode 100644
index 0000000..5f6087c
--- /dev/null
+++ b/internal/notifier/notifiers.go
@@ -0,0 +1,15 @@
+package notifier
+
+import (
+ "donetick.com/core/config"
+ "donetick.com/core/internal/notifier/telegram"
+)
+
+type Notifiers []Notifier
+
+func NewNotifiers(config *config.Config) Notifiers {
+ var notifiers []Notifier
+ notifiers = append(notifiers, telegram.NewTelegramNotifier(config))
+
+ return notifiers
+}
diff --git a/internal/notifier/scheduler.go b/internal/notifier/scheduler.go
index 69470d2..3011c66 100644
--- a/internal/notifier/scheduler.go
+++ b/internal/notifier/scheduler.go
@@ -8,7 +8,6 @@ import (
"donetick.com/core/config"
chRepo "donetick.com/core/internal/chore/repo"
nRepo "donetick.com/core/internal/notifier/repo"
- notifier "donetick.com/core/internal/notifier/telegram"
uRepo "donetick.com/core/internal/user/repo"
"donetick.com/core/logging"
)
@@ -23,12 +22,12 @@ type Scheduler struct {
choreRepo *chRepo.ChoreRepository
userRepo *uRepo.UserRepository
stopChan chan bool
- notifier *notifier.TelegramNotifier
+ notifier Notifier
notificationRepo *nRepo.NotificationRepository
SchedulerJobs config.SchedulerConfig
}
-func NewScheduler(cfg *config.Config, ur *uRepo.UserRepository, cr *chRepo.ChoreRepository, n *notifier.TelegramNotifier, nr *nRepo.NotificationRepository) *Scheduler {
+func NewScheduler(cfg *config.Config, ur *uRepo.UserRepository, cr *chRepo.ChoreRepository, n Notifier, nr *nRepo.NotificationRepository) *Scheduler {
return &Scheduler{
choreRepo: cr,
userRepo: ur,
diff --git a/internal/notifier/telegram/telegram.go b/internal/notifier/telegram/telegram.go
index 3f064b6..eaa89d1 100644
--- a/internal/notifier/telegram/telegram.go
+++ b/internal/notifier/telegram/telegram.go
@@ -19,7 +19,7 @@ type TelegramNotifier struct {
}
func NewTelegramNotifier(config *config.Config) *TelegramNotifier {
- bot, err := tgbotapi.NewBotAPI(config.Telegram.Token)
+ bot, err := tgbotapi.NewBotAPI(config.Notifiers.Telegram.Token)
if err != nil {
fmt.Println("Error creating bot: ", err)
return nil