feat: add notification events handling and MQTT integration

- Implemented notification event publishing with a new NotificationEventPublisher interface.
- Created a noopNotificationEventPublisher for testing purposes.
- Added functionality to publish notification created events via MQTT.
- Introduced a new stream event publisher for handling job logs and updates.
- Added database migration for popup_ads table.
- Created tests for notification events and popup ads functionality.
- Established MQTT connection and publishing helpers for event messages.
This commit is contained in:
2026-03-29 15:47:09 +00:00
parent a910e6c624
commit 863a0ea2f6
42 changed files with 4606 additions and 576 deletions

View File

@@ -36,17 +36,23 @@ type Actor struct {
Role string
}
type Authenticator struct {
db *gorm.DB
logger logger.Logger
trustedMarker string
type NotificationEventPublisher interface {
PublishNotificationCreated(ctx context.Context, notification *model.Notification) error
}
func NewAuthenticator(db *gorm.DB, l logger.Logger, trustedMarker string) *Authenticator {
type Authenticator struct {
db *gorm.DB
logger logger.Logger
trustedMarker string
notificationEvents NotificationEventPublisher
}
func NewAuthenticator(db *gorm.DB, l logger.Logger, trustedMarker string, notificationEvents NotificationEventPublisher) *Authenticator {
return &Authenticator{
db: db,
logger: l,
trustedMarker: strings.TrimSpace(trustedMarker),
db: db,
logger: l,
trustedMarker: strings.TrimSpace(trustedMarker),
notificationEvents: notificationEvents,
}
}
@@ -210,6 +216,11 @@ func (a *Authenticator) maybeCreateSubscriptionReminderPostAuth(ctx context.Cont
if err := tx.WithContext(ctx).Create(notification).Error; err != nil {
return err
}
if a.notificationEvents != nil {
if err := a.notificationEvents.PublishNotificationCreated(ctx, notification); err != nil {
a.logger.Error("Failed to publish notification MQTT event", "error", err, "notification_id", notification.ID, "user_id", notification.UserID)
}
}
return tx.WithContext(ctx).
Model(&model.PlanSubscription{}).
Where("id = ?", subscription.ID).