diff --git a/internal/handler/v2/service/service_read_data_agreement_record.go b/internal/handler/v2/service/service_read_data_agreement_record.go index 13aa5e9..2972855 100644 --- a/internal/handler/v2/service/service_read_data_agreement_record.go +++ b/internal/handler/v2/service/service_read_data_agreement_record.go @@ -2,16 +2,18 @@ package service import ( "encoding/json" + "fmt" "net/http" "github.com/bb-consent/api/internal/common" "github.com/bb-consent/api/internal/config" daRecord "github.com/bb-consent/api/internal/dataagreement_record" + "github.com/bb-consent/api/internal/individual" "github.com/gorilla/mux" ) type readDataAgreementRecordResp struct { - DataAgreementRecord daRecord.DataAgreementRecord `json:"consentRecord"` + DataAgreementRecord interface{} `json:"consentRecord"` } func ServiceReadDataAgreementRecord(w http.ResponseWriter, r *http.Request) { @@ -22,19 +24,30 @@ func ServiceReadDataAgreementRecord(w http.ResponseWriter, r *http.Request) { dataAgreementId := common.Sanitize(mux.Vars(r)[config.DataAgreementId]) + // Repository + individualRepo := individual.IndividualRepository{} + individualRepo.Init(organisationId) + + // fetch the individual + _, err := individualRepo.Get(individualId) + if err != nil { + m := fmt.Sprintf("Failed to fetch individual: %v", individualId) + common.HandleErrorV2(w, http.StatusBadRequest, m, err) + return + } + // Repository darRepo := daRecord.DataAgreementRecordRepository{} darRepo.Init(organisationId) - daRecord, err := darRepo.GetByDataAgreementIdandIndividualId(dataAgreementId, individualId) + var consentRecord interface{} + consentRecord, err = darRepo.GetByDataAgreementIdandIndividualId(dataAgreementId, individualId) if err != nil { - m := "Failed to fetch data agreement record" - common.HandleErrorV2(w, http.StatusInternalServerError, m, err) - return + consentRecord = nil } resp := readDataAgreementRecordResp{ - DataAgreementRecord: daRecord, + DataAgreementRecord: consentRecord, } response, _ := json.Marshal(resp) w.Header().Set(config.ContentTypeHeader, config.ContentTypeJSON)