Skip to content

Commit e66a430

Browse files
author
Santos
committed
delete notifications done
1 parent 83b2acb commit e66a430

File tree

5 files changed

+44
-8
lines changed

5 files changed

+44
-8
lines changed

Struct/struct.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ type Dislikes struct {
139139
}
140140

141141
type Notification struct {
142+
NotifID string
142143
UserName string // the user who done the action
143144
UserAvatar string
144145
Date string

assets/Profil/profil.css

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,18 @@ body {
2525
margin: 0 auto;
2626
}
2727

28+
.delete-profil {
29+
background: transparent;
30+
border: none;
31+
cursor: pointer;
32+
color: #a2a4b4;
33+
}
34+
35+
/* .delete-profil {
36+
margin-left: 90px;
37+
margin-top: -51px;
38+
} */
39+
2840
.left-side {
2941
width: 260px;
3042
border-right: 1px solid #272a3a;

assets/Profil/profil.html

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,16 @@
255255
<div class="username">{{.UserName}}</div>
256256
<p>{{.Action}}</p>
257257
<div class="album-date">{{.Date}}</div>
258+
<form method="post" class="album-action" action="/profil">
259+
<button name="delete-notif" value="{{.NotifID}}" class="delete-profil">
260+
<svg class="delete_svg" stroke="currentColor" stroke-width="2" fill="none" stroke-linecap="round"
261+
stroke-linejoin="round" class="css-i6dzq1" viewBox="0 0 24 24">
262+
<path
263+
d="M17.114,3.923h-4.589V2.427c0-0.252-0.207-0.459-0.46-0.459H7.935c-0.252,0-0.459,0.207-0.459,0.459v1.496h-4.59c-0.252,0-0.459,0.205-0.459,0.459c0,0.252,0.207,0.459,0.459,0.459h1.51v12.732c0,0.252,0.207,0.459,0.459,0.459h10.29c0.254,0,0.459-0.207,0.459-0.459V4.841h1.511c0.252,0,0.459-0.207,0.459-0.459C17.573,4.127,17.366,3.923,17.114,3.923M8.394,2.886h3.214v0.918H8.394V2.886z M14.686,17.114H5.314V4.841h9.372V17.114z M12.525,7.306v7.344c0,0.252-0.207,0.459-0.46,0.459s-0.458-0.207-0.458-0.459V7.306c0-0.254,0.205-0.459,0.458-0.459S12.525,7.051,12.525,7.306M8.394,7.306v7.344c0,0.252-0.207,0.459-0.459,0.459s-0.459-0.207-0.459-0.459V7.306c0-0.254,0.207-0.459,0.459-0.459S8.394,7.051,8.394,7.306">
264+
</path>
265+
</svg>
266+
</button>
267+
</form>
258268
</div>
259269
</div>
260270
{{end}}

data/dataBase.go

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ func CreateDataBase() {
166166
//table notification
167167
_, err = Db.Exec(`CREATE TABLE IF NOT EXISTS notification (
168168
id INTEGER PRIMARY KEY AUTOINCREMENT,
169+
notifid TEXT DEFAULT '',
169170
username TEXT DEFAULT '',
170171
avatar TEXT DEFAULT '',
171172
datetime TEXT DEFAULT '',
@@ -1371,7 +1372,7 @@ func NotifComment(postID string) {
13711372
fmt.Printf("Name of the post : %v\n", namePost)
13721373

13731374
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)
13751376
if err != nil {
13761377
fmt.Println("Error function NotifComment dataBase:")
13771378
fmt.Printf("err: %v\n", err)
@@ -1424,7 +1425,7 @@ func NotifLike(postID string) {
14241425
fmt.Printf("Name of the post : %v\n", namePost)
14251426

14261427
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)
14281429
if err != nil {
14291430
fmt.Println("Error function NotifLike dataBase:")
14301431
fmt.Printf("err: %v\n", err)
@@ -1477,7 +1478,7 @@ func NotifLikeComment(commentID string) {
14771478
fmt.Printf("Name of the post : %v\n", namePost)
14781479

14791480
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)
14811482
if err != nil {
14821483
fmt.Println("Error function NotifLikeCommment dataBase:")
14831484
fmt.Printf("err: %v\n", err)
@@ -1527,7 +1528,7 @@ func NotifDisLike(postID string) {
15271528
fmt.Printf("Name of the post : %v\n", namePost)
15281529

15291530
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)
15311532
if err != nil {
15321533
fmt.Println("Error function NotifDislike dataBase:")
15331534
fmt.Printf("err: %v\n", err)
@@ -1577,7 +1578,7 @@ func NotifDisLikeComment(commentID string) {
15771578
}
15781579
}
15791580

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)
15811582
if err != nil {
15821583
fmt.Println("Error function NotifDislikeComment dataBase:")
15831584
fmt.Printf("err: %v\n", err)
@@ -1620,19 +1621,19 @@ func GetUserNotif() []structure.Notification {
16201621
}
16211622
var Notifs []structure.Notification
16221623

1623-
var name, picture, date, postID, commentID, action string
1624+
var notifID, name, picture, date, postID, commentID, action string
16241625
var likePost, dislikePost, likeComment, dislikeComment, addedComment bool
16251626

16261627
for rows.Next() {
16271628

16281629
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)
16301631
if err != nil {
16311632
panic(err)
16321633
}
16331634

16341635
Notifs = reverseApppend(Notifs, structure.Notification{
1635-
1636+
NotifID: notifID,
16361637
UserName: name,
16371638
UserAvatar: picture,
16381639
Date: date,
@@ -1664,3 +1665,11 @@ func LenUserNotif(username string) int {
16641665
}
16651666
return count
16661667
}
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+
}

server.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,10 @@ func profil(w http.ResponseWriter, r *http.Request) {
641641

642642
data.AddingModoRequest(user.Name, user.Image, script.GeneratePostID(), time.Now().Format("15:04 2-Janv-2006"))
643643

644+
}
645+
if r.FormValue("delete-notif") != "" {
646+
data.DeleteNotif(r.FormValue("delete-notif"))
647+
644648
}
645649

646650
notification = data.GetUserNotif()

0 commit comments

Comments
 (0)