Added notificaiton model

This commit is contained in:
Nedim
2023-10-09 18:23:44 +02:00
parent 00d15ebe7e
commit abe79e5556
8 changed files with 249 additions and 10 deletions

View File

@@ -1,11 +1,31 @@
package messaging
package notification
import (
"fmt"
"github.com/jinzhu/gorm"
"gitlab.com/pactual1/backend/models"
)
func MessagingService(ch chan string) {
for msg := range ch {
fmt.Println("Messaging Service: ", msg)
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)
}
}
}