Files
old-backend/services/messaging/messaging_service.go

31 lines
587 B
Go
Raw Normal View History

2023-10-09 18:23:44 +02:00
package notification
import (
"fmt"
2023-10-09 18:23:44 +02:00
"github.com/jinzhu/gorm"
"gitlab.com/pactual1/backend/models"
)
2023-10-09 18:23:44 +02:00
type service struct {
ch chan models.Notification
db *gorm.DB
}
func NewService(ch chan models.Notification, db *gorm.DB) service {
return service{
ch: ch,
db: db,
}
}
2023-10-09 18:23:44 +02:00
func (s service) MessagingService() {
for notification := range s.ch {
fmt.Println("Messaging Service received: ", notification)
// Save the notification to the database
if err := s.db.Create(&notification).Error; err != nil {
fmt.Printf("Error saving notification to DB: %v\n", err)
}
}
}