From 50d4e155bce65f6960f0e546e9f889c6aa5d4281 Mon Sep 17 00:00:00 2001 From: Albin Antony Date: Fri, 24 Nov 2023 12:37:55 +0530 Subject: [PATCH] Fix #584 The individual attempts to OPT-IN or OPT-OUT to multiple DA(s) records should be listed in the consent records according to timestamp --- .../handler/v2/audit/audit_list_dataagreement_records.go | 9 +++++++++ 1 file changed, 9 insertions(+) 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,