diff --git a/api/v1/models.go b/api/v1/models.go index 1166c371..094d7e4e 100644 --- a/api/v1/models.go +++ b/api/v1/models.go @@ -198,7 +198,7 @@ type Notification struct { New *VulnerabilityWithLayers `json:"New,omitempty"` } -func NotificationFromDatabaseModel(dbNotification database.VulnerabilityNotification, limit int, page, nextPage database.VulnerabilityNotificationPageNumber, key string) Notification { +func NotificationFromDatabaseModel(dbNotification database.VulnerabilityNotification, limit int, pageToken string, nextPage database.VulnerabilityNotificationPageNumber, key string) Notification { var oldVuln *VulnerabilityWithLayers if dbNotification.OldVulnerability != nil { v := VulnerabilityWithLayersFromDatabaseModel(*dbNotification.OldVulnerability) @@ -235,7 +235,7 @@ func NotificationFromDatabaseModel(dbNotification database.VulnerabilityNotifica Notified: notified, Deleted: deleted, Limit: limit, - Page: pageNumberToToken(page, key), + Page: pageToken, NextPage: nextPageStr, Old: oldVuln, New: newVuln, diff --git a/api/v1/routes.go b/api/v1/routes.go index f8792e20..f380ac5c 100644 --- a/api/v1/routes.go +++ b/api/v1/routes.go @@ -381,6 +381,7 @@ func getNotification(w http.ResponseWriter, r *http.Request, p httprouter.Params return getNotificationRoute, http.StatusBadRequest } + var pageToken string page := database.VulnerabilityNotificationFirstPage pageStrs, pageExists := query["page"] if pageExists { @@ -389,6 +390,9 @@ func getNotification(w http.ResponseWriter, r *http.Request, p httprouter.Params writeResponse(w, r, http.StatusBadRequest, NotificationEnvelope{Error: &Error{"invalid page format: " + err.Error()}}) return getNotificationRoute, http.StatusBadRequest } + pageToken = pageStrs[0] + } else { + pageToken = pageNumberToToken(page, ctx.Config.PaginationKey) } dbNotification, nextPage, err := ctx.Store.GetNotification(p.ByName("notificationName"), limit, page) @@ -400,7 +404,7 @@ func getNotification(w http.ResponseWriter, r *http.Request, p httprouter.Params return getNotificationRoute, http.StatusInternalServerError } - notification := NotificationFromDatabaseModel(dbNotification, limit, page, nextPage, ctx.Config.PaginationKey) + notification := NotificationFromDatabaseModel(dbNotification, limit, pageToken, nextPage, ctx.Config.PaginationKey) writeResponse(w, r, http.StatusOK, NotificationEnvelope{Notification: ¬ification}) return getNotificationRoute, http.StatusOK