From fb910bf60d5b8aa3218218a803914c23d3a45071 Mon Sep 17 00:00:00 2001 From: Stephen Adamson Date: Sat, 20 Jun 2026 16:58:51 +0100 Subject: [PATCH] feat(backend): migrate notification IDs from int to string and update cursor format Change notification ID type from int to string (CHAR(12)) to match the schema migration. - Update AdminNotification.ID field to string - Change cursor format from int-based to string-based for pagination - Use validators.IsValidID instead of strconv.Atoi for notification ID validation - Update cursor format to use RFC3339Nano for precision Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus --- backend/handlers/notifications/notifications.go | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) 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 }