Added notificaiton model
This commit is contained in:
@@ -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(¬ification).Error; err != nil {
|
||||
fmt.Printf("Error saving notification to DB: %v\n", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user