diff --git a/backend/handlers/notifications/notifications.go b/backend/handlers/notifications/notifications.go index cecfdc4..89f9c7e 100644 --- a/backend/handlers/notifications/notifications.go +++ b/backend/handlers/notifications/notifications.go @@ -18,7 +18,7 @@ import ( // Structs returned in JSON type AdminNotification struct { - ID int `json:"id"` + ID string `json:"id"` Reason string `json:"reason"` BookingID *string `json:"booking_id,omitempty"` UserID *string `json:"user_id,omitempty"` @@ -185,7 +185,7 @@ func GetNotifications(w http.ResponseWriter, r *http.Request) { if len(notifications) > perPage { notifications = notifications[:perPage] last := notifications[len(notifications)-1] - cursor := last.CreatedAt.Format(time.RFC3339) + "|" + strconv.Itoa(last.ID) + cursor := last.CreatedAt.Format(time.RFC3339Nano) + "|" + last.ID nextCursor = &cursor } @@ -227,12 +227,7 @@ func GetUnreadCount(w http.ResponseWriter, r *http.Request) { func AcknowledgeNotification(w http.ResponseWriter, r *http.Request) { idStr := chi.URLParam(r, "id") - if idStr == "" { - http.Error(w, "missing notification ID", http.StatusBadRequest) - return - } - id, err := strconv.Atoi(idStr) - if err != nil || id <= 0 { + if idStr == "" || !validators.IsValidID(idStr) { http.Error(w, "invalid notification ID", http.StatusBadRequest) return } @@ -243,9 +238,9 @@ func AcknowledgeNotification(w http.ResponseWriter, r *http.Request) { WHERE id = $1 AND acknowledged_at IS NULL ` - cmdTag, err := db.DB.Exec(r.Context(), query, id) + cmdTag, err := db.DB.Exec(r.Context(), query, idStr) if err != nil { - log.Printf("Failed to acknowledge notification %d: %v", id, err) + log.Printf("Failed to acknowledge notification %s: %v", idStr, err) http.Error(w, "Internal server error", http.StatusInternalServerError) return }