Skip to content

Commit 39f83d7

Browse files
committed
fix: update NotificationRequestDTO to include BSON field names for setting and channel
1 parent 196273c commit 39f83d7

2 files changed

Lines changed: 20 additions & 9 deletions

File tree

core/models/models/notification_request.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@ type NotificationRequest struct {
2424
type NotificationRequestDTO struct {
2525
NotificationRequest `json:",inline" bson:",inline"`
2626

27-
Setting *NotificationSetting `json:"setting,omitempty" bson:"-"`
28-
Channel *NotificationChannel `json:"channel,omitempty" bson:"-"`
27+
Setting *NotificationSetting `json:"setting,omitempty" bson:"_setting,omitempty"`
28+
Channel *NotificationChannel `json:"channel,omitempty" bson:"_channel,omitempty"`
2929
}

core/notification/service.go

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func (svc *Service) Send(s *models.NotificationSetting, args ...any) {
5656
case TypeMail:
5757
svc.SendMail(s, ch, title, content)
5858
case TypeIM:
59-
svc.SendIM(ch, title, content)
59+
svc.SendIM(s, ch, title, content)
6060
}
6161
}(chId)
6262
}
@@ -81,9 +81,9 @@ func (svc *Service) SendMail(s *models.NotificationSetting, ch *models.Notificat
8181
svc.saveRequest(r, err)
8282
}
8383

84-
func (svc *Service) SendIM(ch *models.NotificationChannel, title, content string) {
84+
func (svc *Service) SendIM(s *models.NotificationSetting, ch *models.NotificationChannel, title, content string) {
8585
// request
86-
r, _ := svc.createRequestIM(ch, title, content, false)
86+
r, _ := svc.createRequestIM(s, ch, title, content, false)
8787

8888
// send mobile notification
8989
err := SendIMNotification(ch, title, content)
@@ -119,7 +119,7 @@ func (svc *Service) SendTestMessage(locale string, ch *models.NotificationChanne
119119
}
120120

121121
// Create request
122-
r, _ = svc.createRequestMailTest(ch, title, content, toMail)
122+
r, _ = svc.createRequestMailTest(nil, ch, title, content, toMail)
123123

124124
// For email
125125
err = SendMail(nil, ch, toMail, nil, nil, title, content)
@@ -129,7 +129,7 @@ func (svc *Service) SendTestMessage(locale string, ch *models.NotificationChanne
129129

130130
case TypeIM:
131131
// Create request
132-
r, _ = svc.createRequestIM(ch, title, content, true)
132+
r, _ = svc.createRequestIM(nil, ch, title, content, true)
133133

134134
// For instant messaging
135135
err = SendIMNotification(ch, title, content)
@@ -580,7 +580,7 @@ func (svc *Service) createRequestMail(s *models.NotificationSetting, ch *models.
580580
return &r, nil
581581
}
582582

583-
func (svc *Service) createRequestMailTest(ch *models.NotificationChannel, title, content string, mailTo []string) (res *models.NotificationRequest, err error) {
583+
func (svc *Service) createRequestMailTest(s *models.NotificationSetting, ch *models.NotificationChannel, title, content string, mailTo []string) (res *models.NotificationRequest, err error) {
584584
if mailTo == nil {
585585
mailTo = []string{ch.SMTPUsername}
586586
}
@@ -596,6 +596,11 @@ func (svc *Service) createRequestMailTest(ch *models.NotificationChannel, title,
596596
Test: true,
597597
}
598598

599+
// Set SettingId if setting is provided (for non-test requests)
600+
if s != nil {
601+
r.SettingId = s.Id
602+
}
603+
599604
r.SetCreatedAt(time.Now())
600605
r.SetUpdatedAt(time.Now())
601606
r.Id, err = service.NewModelService[models.NotificationRequest]().InsertOne(r)
@@ -606,14 +611,20 @@ func (svc *Service) createRequestMailTest(ch *models.NotificationChannel, title,
606611
return &r, nil
607612
}
608613

609-
func (svc *Service) createRequestIM(ch *models.NotificationChannel, title, content string, test bool) (res *models.NotificationRequest, err error) {
614+
func (svc *Service) createRequestIM(s *models.NotificationSetting, ch *models.NotificationChannel, title, content string, test bool) (res *models.NotificationRequest, err error) {
610615
r := models.NotificationRequest{
611616
Status: StatusSending,
612617
ChannelId: ch.Id,
613618
Title: title,
614619
Content: content,
615620
Test: test,
616621
}
622+
623+
// Set SettingId if setting is provided (for non-test requests)
624+
if s != nil {
625+
r.SettingId = s.Id
626+
}
627+
617628
r.SetCreatedAt(time.Now())
618629
r.SetUpdatedAt(time.Now())
619630
r.Id, err = service.NewModelService[models.NotificationRequest]().InsertOne(r)

0 commit comments

Comments
 (0)