Skip to content

Commit a43c3f4

Browse files
committed
notfications fix
Signed-off-by: Dhruv Jain <92215138+jaydee029@users.noreply.github.com>
1 parent dcbb1a7 commit a43c3f4

File tree

9 files changed

+15
-34
lines changed

9 files changed

+15
-34
lines changed

api/handler/notifications.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,14 +151,15 @@ func (cfg *Handler) ReadNotification(w http.ResponseWriter, r *http.Request) {
151151
var userid pgtype.UUID
152152
err := userid.Scan(useridstr)
153153
if err != nil {
154+
cfg.logger.Info("Error setting UUID:", zap.Error(err))
154155
respondWithError(w, http.StatusInternalServerError, err.Error())
155156
return
156157
}
157158

158159
var notificationid pgtype.UUID
159160
err = notificationid.Scan(useridstr)
160161
if err != nil {
161-
cfg.logger.Info("Error setting UUID:", zap.Error(err))
162+
cfg.logger.Info("Error setting notification ID:", zap.Error(err))
162163
respondWithError(w, http.StatusInternalServerError, err.Error())
163164
return
164165
}
@@ -169,10 +170,11 @@ func (cfg *Handler) ReadNotification(w http.ResponseWriter, r *http.Request) {
169170
})
170171

171172
if err != nil {
173+
cfg.logger.Info("error while reading notification", zap.Error(err))
172174
respondWithError(w, http.StatusInternalServerError, err.Error())
173175
}
174176

175-
respondWithJson(w, http.StatusNoContent, "Notification Read")
177+
respondWithJson(w, http.StatusOK, "Notification Read")
176178
}
177179

178180
func (cfg *Handler) ReadNotifications(w http.ResponseWriter, r *http.Request) {

internal/database/notification.sql.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sql/queries/notification.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ ORDER BY generated_at DESC
55
LIMIT $3;
66

77
-- name: ReadNotificationSingle :exec
8-
UPDATE notifications SET read= true WHERE user_id=$1 AND id=$2;
8+
UPDATE notifications SET read=true WHERE user_id=$1 AND id=$2;
99

1010

1111
-- name: ReadNotificationAll :exec
@@ -28,6 +28,6 @@ AND generated_at=$2
2828
WHERE id=$3 RETURNING actors;
2929

3030
-- name: InsertCommentNotification :one
31-
INSERT INTO notifications(id, user_id,actors,type,prose_id,generated_at ) VALUES($1,$2,$3, 'comment',$4,$5) ON CONFLICT (user_id,prose_id,actors,type,read)
31+
INSERT INTO notifications(id, user_id,actors,type,prose_id,generated_at ) VALUES($1,$2,$3, 'comment',$4,$5) ON CONFLICT (user_id,prose_id,type,read)
3232
DO UPDATE SET actors= notifications.actors || $3, generated_at=$5
3333
RETURNING id,generated_at,actors;

sql/schema/010_notifications.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
CREATE TABLE notifications(
33
id uuid PRIMARY KEY,
44
user_id uuid NOT NULL,
5-
prose_id uuid UNIQUE,
5+
prose_id uuid NOT NULL,
66
actors VARCHAR [] ,
77
generated_at TIMESTAMP NOT NULL,
8-
type VARCHAR(12) NOT NULL,
8+
type VARCHAR(15) NOT NULL,
99
read BOOLEAN NOT NULL DEFAULT false
1010
);
1111

sql/schema/011_notification.sql

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
-- +goose Up
2+
ALTER TABLE notifications ADD CONSTRAINT unique_comment_notification UNIQUE (user_id, prose_id, type, read);
3+
4+
-- +goose Down
5+
ALTER TABLE notifications DROP CONSTRAINT unique_comment_notification;

sql/schema/011_notifications.sql

Lines changed: 0 additions & 7 deletions
This file was deleted.

sql/schema/012_notification.sql

Lines changed: 0 additions & 7 deletions
This file was deleted.

sql/schema/013_notifications.sql

Lines changed: 0 additions & 7 deletions
This file was deleted.

sql/schema/014_notifications.sql

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)