Skip to content

Commit

Permalink
Fix #514 READ - Read data agreement record
Browse files Browse the repository at this point in the history
  • Loading branch information
albinpa authored and georgepadayatti committed Nov 13, 2023
1 parent 72bada5 commit 057696c
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions internal/handler/v2/service/service_read_data_agreement_record.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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)
Expand Down

0 comments on commit 057696c

Please sign in to comment.