@@ -166,6 +166,7 @@ func CreateDataBase() {
166
166
//table notification
167
167
_ , err = Db .Exec (`CREATE TABLE IF NOT EXISTS notification (
168
168
id INTEGER PRIMARY KEY AUTOINCREMENT,
169
+ notifid TEXT DEFAULT '',
169
170
username TEXT DEFAULT '',
170
171
avatar TEXT DEFAULT '',
171
172
datetime TEXT DEFAULT '',
@@ -1371,7 +1372,7 @@ func NotifComment(postID string) {
1371
1372
fmt .Printf ("Name of the post : %v\n " , namePost )
1372
1373
1373
1374
dateTime := time .Now ().Format ("1-Janv-2006 15:04" )
1374
- _ , err = Db .Exec ("INSERT INTO notification (username, avatar, datetime, post_id, comment_id, added_comment) VALUES (?,?,?,?,?,?)" , namePost , picture , dateTime , postID , commentID , true )
1375
+ _ , err = Db .Exec ("INSERT INTO notification (notifid, username, avatar, datetime, post_id, comment_id, added_comment) VALUES (?,?,?,?,?,?,?)" , script . GenerateRandomString () , namePost , picture , dateTime , postID , commentID , true )
1375
1376
if err != nil {
1376
1377
fmt .Println ("Error function NotifComment dataBase:" )
1377
1378
fmt .Printf ("err: %v\n " , err )
@@ -1424,7 +1425,7 @@ func NotifLike(postID string) {
1424
1425
fmt .Printf ("Name of the post : %v\n " , namePost )
1425
1426
1426
1427
dateTime := time .Now ().Format ("1-Janv-2006 15:04" )
1427
- _ , err = Db .Exec ("INSERT INTO notification (username, avatar, datetime, post_id, like_post) VALUES (?,?,?,?,?)" , namePost , picture , dateTime , postID , true )
1428
+ _ , err = Db .Exec ("INSERT INTO notification (notifid, username, avatar, datetime, post_id, like_post) VALUES (?,?,?,?,?,?)" , script . GenerateRandomString () , namePost , picture , dateTime , postID , true )
1428
1429
if err != nil {
1429
1430
fmt .Println ("Error function NotifLike dataBase:" )
1430
1431
fmt .Printf ("err: %v\n " , err )
@@ -1477,7 +1478,7 @@ func NotifLikeComment(commentID string) {
1477
1478
fmt .Printf ("Name of the post : %v\n " , namePost )
1478
1479
1479
1480
dateTime := time .Now ().Format ("1-Janv-2006 15:04" )
1480
- _ , err = Db .Exec ("INSERT INTO notification (username, avatar, datetime, comment_id,like_comment) VALUES (?,?,?,?,?)" , namePost , picture , dateTime , commentID , true )
1481
+ _ , err = Db .Exec ("INSERT INTO notification (notifid, username, avatar, datetime, comment_id,like_comment) VALUES (?,?,?,?,?,?)" , script . GenerateRandomString () , namePost , picture , dateTime , commentID , true )
1481
1482
if err != nil {
1482
1483
fmt .Println ("Error function NotifLikeCommment dataBase:" )
1483
1484
fmt .Printf ("err: %v\n " , err )
@@ -1527,7 +1528,7 @@ func NotifDisLike(postID string) {
1527
1528
fmt .Printf ("Name of the post : %v\n " , namePost )
1528
1529
1529
1530
dateTime := time .Now ().Format ("1-Janv-2023 15:04" )
1530
- _ , err = Db .Exec ("INSERT INTO notification (username, avatar, datetime, post_id, dislike_post) VALUES (?,?,?,?,?)" , namePost , picture , dateTime , postID , true )
1531
+ _ , err = Db .Exec ("INSERT INTO notification (notifid, username, avatar, datetime, post_id, dislike_post) VALUES (?,?,?,?,?,?)" , script . GenerateRandomString () , namePost , picture , dateTime , postID , true )
1531
1532
if err != nil {
1532
1533
fmt .Println ("Error function NotifDislike dataBase:" )
1533
1534
fmt .Printf ("err: %v\n " , err )
@@ -1577,7 +1578,7 @@ func NotifDisLikeComment(commentID string) {
1577
1578
}
1578
1579
}
1579
1580
1580
- _ , err = Db .Exec ("INSERT INTO notification (username,avatar, datetime,comment_id,dislike_comment) VALUES (?,?,?,?,?)" , nameNotif , picture , dateTime , commentID , dislikeComment )
1581
+ _ , err = Db .Exec ("INSERT INTO notification (notifid, username,avatar, datetime,comment_id,dislike_comment) VALUES (?,?,?,?,?,?)" , script . GenerateRandomString () , nameNotif , picture , dateTime , commentID , dislikeComment )
1581
1582
if err != nil {
1582
1583
fmt .Println ("Error function NotifDislikeComment dataBase:" )
1583
1584
fmt .Printf ("err: %v\n " , err )
@@ -1620,19 +1621,19 @@ func GetUserNotif() []structure.Notification {
1620
1621
}
1621
1622
var Notifs []structure.Notification
1622
1623
1623
- var name , picture , date , postID , commentID , action string
1624
+ var notifID , name , picture , date , postID , commentID , action string
1624
1625
var likePost , dislikePost , likeComment , dislikeComment , addedComment bool
1625
1626
1626
1627
for rows .Next () {
1627
1628
1628
1629
var id int
1629
- err := rows .Scan (& id , & name , & picture , & date , & postID , & commentID , & likePost , & dislikePost , & likeComment , & dislikeComment , & addedComment , & action )
1630
+ err := rows .Scan (& id , & notifID , & name , & picture , & date , & postID , & commentID , & likePost , & dislikePost , & likeComment , & dislikeComment , & addedComment , & action )
1630
1631
if err != nil {
1631
1632
panic (err )
1632
1633
}
1633
1634
1634
1635
Notifs = reverseApppend (Notifs , structure.Notification {
1635
-
1636
+ NotifID : notifID ,
1636
1637
UserName : name ,
1637
1638
UserAvatar : picture ,
1638
1639
Date : date ,
@@ -1664,3 +1665,11 @@ func LenUserNotif(username string) int {
1664
1665
}
1665
1666
return count
1666
1667
}
1668
+
1669
+ func DeleteNotif (notifID string ) {
1670
+ _ , err := Db .Exec ("DELETE FROM notification WHERE notifid=?" , notifID )
1671
+ if err != nil {
1672
+ fmt .Println ("Error function DeleteNotif dataBase:" )
1673
+ fmt .Printf ("err: %v\n " , err )
1674
+ }
1675
+ }
0 commit comments