From d8e742da9dcdd33ffef8ea851949e42895cf0b74 Mon Sep 17 00:00:00 2001 From: Albin Antony Date: Wed, 15 Nov 2023 20:19:23 +0530 Subject: [PATCH] Fix #571 Normalise the usage purpose before checking if it exists to avoid duplication --- .../v2/config/dataagreement/config_create_dataagreement.go | 3 ++- .../v2/config/dataagreement/config_update_dataagreement.go | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/internal/handler/v2/config/dataagreement/config_create_dataagreement.go b/internal/handler/v2/config/dataagreement/config_create_dataagreement.go index 81f52f4..d902ea7 100644 --- a/internal/handler/v2/config/dataagreement/config_create_dataagreement.go +++ b/internal/handler/v2/config/dataagreement/config_create_dataagreement.go @@ -6,6 +6,7 @@ import ( "fmt" "io" "net/http" + "strings" "github.com/bb-consent/api/internal/common" "github.com/bb-consent/api/internal/config" @@ -274,7 +275,7 @@ func ConfigCreateDataAgreement(w http.ResponseWriter, r *http.Request) { darepo := dataagreement.DataAgreementRepository{} darepo.Init(organisationId) - count, err := darepo.CountDocumentsByPurpose(dataAgreementReq.DataAgreement.Purpose) + count, err := darepo.CountDocumentsByPurpose(strings.TrimSpace(dataAgreementReq.DataAgreement.Purpose)) if err != nil { m := "Failed to count data agreement by purpose" common.HandleErrorV2(w, http.StatusNotFound, m, err) diff --git a/internal/handler/v2/config/dataagreement/config_update_dataagreement.go b/internal/handler/v2/config/dataagreement/config_update_dataagreement.go index 2c571f3..6125210 100644 --- a/internal/handler/v2/config/dataagreement/config_update_dataagreement.go +++ b/internal/handler/v2/config/dataagreement/config_update_dataagreement.go @@ -6,6 +6,7 @@ import ( "fmt" "io" "net/http" + "strings" "github.com/bb-consent/api/internal/common" "github.com/bb-consent/api/internal/config" @@ -167,7 +168,7 @@ func ConfigUpdateDataAgreement(w http.ResponseWriter, r *http.Request) { daRepo := dataagreement.DataAgreementRepository{} daRepo.Init(organisationId) - count, err := daRepo.CountDocumentsByPurposeExeptOneDataAgreement(dataAgreementReq.DataAgreement.Purpose, dataAgreementId) + count, err := daRepo.CountDocumentsByPurposeExeptOneDataAgreement(strings.TrimSpace(dataAgreementReq.DataAgreement.Purpose), dataAgreementId) if err != nil { m := "Failed to count data agreements by purpose" common.HandleErrorV2(w, http.StatusNotFound, m, err)