Files
old-backend/services/messaging/messaging_service.go
2023-10-16 13:11:40 +02:00

31 lines
587 B
Go

package notification
import (
"fmt"
"github.com/jinzhu/gorm"
"gitlab.com/pactual1/backend/models"
)
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,
}
}
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)
}
}
}