From bb7ef6cbf3c4199b732aadead958d2190547c1c0 Mon Sep 17 00:00:00 2001 From: Jony Bepary Date: Sat, 21 Oct 2023 17:42:15 +0600 Subject: [PATCH] #Add notification Struct and Message to the model --- internal/model/notifications.go | 68 +++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) mode change 100644 => 100755 internal/model/notifications.go diff --git a/internal/model/notifications.go b/internal/model/notifications.go old mode 100644 new mode 100755 index 8b53790..7661810 --- a/internal/model/notifications.go +++ b/internal/model/notifications.go @@ -1 +1,69 @@ package model + +import ( + "github.com/SohelAhmedJoni/Awazz-Backend/internal/durable" +) + +func (n *Notifications) SaveNotifications() error { + db, err := durable.CreateDatabase("Database/notifications.sqlite") + if err != nil { + return err + } + defer db.Close() + str := ` + CREATE TABLE IF NOT EXISTS Messages ( + Title VARCHAR(128), + Body VARCHAR(128), + Source VARCHAR(128), + Image VARCHAR(128), + Sound VARCHAR(128), + Time TIMESTAMP, + Channel VARCHAR(128), + PriorityLevel INT, + ReadStatus bool, + Created TIMESTAMP) + ` + _, err = db.Exec(str) + if err != nil { + return err + } + str2 := ` +INSERT INTO Messages (Title,Body,Source,Image,Sound,Time,Channel,PriorityLevel,ReadStatus,Created) VALUES (?,?,?,?,?,?,?,?,?,?); + ` + statement, err := db.Prepare(str2) + if err != nil { + return err + } + _, err = statement.Exec(n.Title, n.Body, n.Source, n.Image, n.Sound, n.Time, n.Channel, n.PriorityLevel, n.ReadStatus, n.Created) + if err != nil { + return err + } + + return nil +} + +/*func (n *Notifications) GetNotifications() error { + db, err := durable.CreateDatabase("Database/notifications") + if err != nil { + return err + } + defer db.Close() + return nil +} +func (n *Notifications) UpdateNotifications() error { + db, err := durable.CreateDatabase("Database/notifications") + if err != nil { + return err + } + defer db.Close() + return nil +} +func (n *Notifications) DeleteNotifications() error { + db, err := durable.CreateDatabase("Database/notifications") + if err != nil { + return err + } + defer db.Close() + return nil +} +*/