diff --git a/internal/handler/v2/audit/audit_list_dataagreement_records.go b/internal/handler/v2/audit/audit_list_dataagreement_records.go index 046c070..377cfa2 100644 --- a/internal/handler/v2/audit/audit_list_dataagreement_records.go +++ b/internal/handler/v2/audit/audit_list_dataagreement_records.go @@ -5,6 +5,8 @@ import ( "errors" "log" "net/http" + "sort" + "time" "github.com/bb-consent/api/internal/common" "github.com/bb-consent/api/internal/config" @@ -144,6 +146,13 @@ func AuditListDataAgreementRecords(w http.ResponseWriter, r *http.Request) { return } + // Sort the consentRecords based on timestamp + sort.SliceStable(consentRecords, func(i, j int) bool { + timeI, _ := time.Parse(time.RFC3339, consentRecords[i].Timestamp) + timeJ, _ := time.Parse(time.RFC3339, consentRecords[j].Timestamp) + return timeI.After(timeJ) + }) + query := paginate.PaginateObjectsQuery{ Limit: limit, Offset: offset,