-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnotifycomment.go
52 lines (42 loc) · 1.25 KB
/
notifycomment.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package main
import (
"context"
"log"
"time"
"github.com/google/uuid"
"github.com/jackc/pgx/v5/pgtype"
"github.com/jaydee029/Verses/internal/database"
)
func (cfg *apiconfig) CommentNotification(c Comment) {
nid := uuid.New()
var nid_pgtype pgtype.UUID
if err := nid_pgtype.Scan(nid); err != nil {
log.Println("error while converting notification id to pgtype:" + err.Error())
return
}
generated_at := time.Now().UTC()
var generated_at_pgtype pgtype.Timestamp
if err := generated_at_pgtype.Scan(generated_at); err != nil {
log.Println("error while converting timestamp to pgtype:" + err.Error())
return
}
notification, err := cfg.DB.InsertCommentNotification(context.Background(), database.InsertCommentNotificationParams{
UserID: c.Userid,
ProseID: c.Proseid,
GeneratedAt: generated_at_pgtype,
ID: nid_pgtype,
Actors: []string{c.Username},
})
if err != nil {
log.Println("error while inserting comment notifications:" + err.Error())
return
}
var n Notification
n.ID = nid_pgtype
n.Actors = notification.Actors
n.Userid = c.Userid
n.Proseid = c.Proseid
n.Generated_at = notification.GeneratedAt
n.Type = "comment"
go cfg.Broadcastnotifications(n)
}