Skip to content

Commit

Permalink
Fix #607 Update data agreement endpoint to return 400 status code if …
Browse files Browse the repository at this point in the history
…not present
  • Loading branch information
albinpa committed Jan 4, 2024
1 parent 4cd6b2c commit 68eb1b6
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ func ConfigCreateDataAgreement(w http.ResponseWriter, r *http.Request) {
o, err := org.Get(organisationId)
if err != nil {
m := fmt.Sprintf("Failed to get organization by ID :%v", organisationId)
common.HandleErrorV2(w, http.StatusNotFound, m, err)
common.HandleErrorV2(w, http.StatusBadRequest, m, err)
return
}
// Repository
Expand All @@ -297,7 +297,7 @@ func ConfigCreateDataAgreement(w http.ResponseWriter, r *http.Request) {
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)
common.HandleErrorV2(w, http.StatusBadRequest, m, err)
return
}
if count >= 1 {
Expand Down Expand Up @@ -328,7 +328,7 @@ func ConfigCreateDataAgreement(w http.ResponseWriter, r *http.Request) {
newRevision, err = revision.UpdateRevisionForDataAgreement(newDataAgreement, orgAdminId)
if err != nil {
m := "Failed to create data agreement"
common.HandleErrorV2(w, http.StatusInternalServerError, m, err)
common.HandleErrorV2(w, http.StatusBadRequest, m, err)
return
}

Expand All @@ -338,7 +338,7 @@ func ConfigCreateDataAgreement(w http.ResponseWriter, r *http.Request) {
newRevision, err = revision.CreateRevisionForDraftDataAgreement(newDataAgreement, orgAdminId)
if err != nil {
m := "Failed to create revision for draft data agreement"
common.HandleErrorV2(w, http.StatusInternalServerError, m, err)
common.HandleErrorV2(w, http.StatusBadRequest, m, err)
return
}

Expand All @@ -348,7 +348,7 @@ func ConfigCreateDataAgreement(w http.ResponseWriter, r *http.Request) {
savedDataAgreement, err := darepo.Add(newDataAgreement)
if err != nil {
m := fmt.Sprintf("Failed to create new data agreement: %v", newDataAgreement.Id)
common.HandleErrorV2(w, http.StatusInternalServerError, m, err)
common.HandleErrorV2(w, http.StatusBadRequest, m, err)
return
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func ConfigDeleteDataAgreement(w http.ResponseWriter, r *http.Request) {
toBeDeletedDA, err := daRepo.Get(dataAgreementId)
if err != nil {
m := fmt.Sprintf("Failed to fetch data agreement: %v", dataAgreementId)
common.HandleErrorV2(w, http.StatusInternalServerError, m, err)
common.HandleErrorV2(w, http.StatusBadRequest, m, err)
return
}

Expand All @@ -46,7 +46,7 @@ func ConfigDeleteDataAgreement(w http.ResponseWriter, r *http.Request) {
rev, err = revision.GetLatestByDataAgreementId(dataAgreementId)
if err != nil {
m := fmt.Sprintf("Failed to fetch revision: %v", dataAgreementId)
common.HandleErrorV2(w, http.StatusInternalServerError, m, err)
common.HandleErrorV2(w, http.StatusBadRequest, m, err)
return
}

Expand All @@ -56,7 +56,7 @@ func ConfigDeleteDataAgreement(w http.ResponseWriter, r *http.Request) {
rev, err = revision.CreateRevisionForDraftDataAgreement(toBeDeletedDA, orgAdminId)
if err != nil {
m := "Failed to create revision in run time"
common.HandleErrorV2(w, http.StatusInternalServerError, m, err)
common.HandleErrorV2(w, http.StatusBadRequest, m, err)
return
}

Expand All @@ -73,7 +73,7 @@ func ConfigDeleteDataAgreement(w http.ResponseWriter, r *http.Request) {
_, err = daRepo.Update(toBeDeletedDA)
if err != nil {
m := fmt.Sprintf("Failed to delete data agreement: %v", dataAgreementId)
common.HandleErrorV2(w, http.StatusInternalServerError, m, err)
common.HandleErrorV2(w, http.StatusBadRequest, m, err)
return
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ func ConfigListDataAgreementRevisions(w http.ResponseWriter, r *http.Request) {
da, err := daRepo.Get(dataAgreementId)
if err != nil {
m := fmt.Sprintf("Failed to fetch data agreement: %v", dataAgreementId)
common.HandleErrorV2(w, http.StatusInternalServerError, m, err)
common.HandleErrorV2(w, http.StatusBadRequest, m, err)
return
}

revisions, err := revision.ListAllByDataAgreementId(dataAgreementId)
if err != nil {
m := fmt.Sprintf("Failed to fetch revision: %v", dataAgreementId)
common.HandleErrorV2(w, http.StatusInternalServerError, m, err)
common.HandleErrorV2(w, http.StatusBadRequest, m, err)
return
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ func ConfigListDataAgreements(w http.ResponseWriter, r *http.Request) {
includeRevisions, err := parseIncludeRevisionsQueryParams(r)
if err != nil {
m := "Failed to parse query param includeRevisions"
common.HandleErrorV2(w, http.StatusInternalServerError, m, err)
common.HandleErrorV2(w, http.StatusBadRequest, m, err)
return
}

Expand All @@ -300,7 +300,7 @@ func ConfigListDataAgreements(w http.ResponseWriter, r *http.Request) {
dataAgreements, err := getDataAgreementsWithRevisions(organisationId, lifecycle)
if err != nil {
m := "Failed to fetch data agreements"
common.HandleErrorV2(w, http.StatusInternalServerError, m, err)
common.HandleErrorV2(w, http.StatusBadRequest, m, err)
return
}

Expand Down Expand Up @@ -346,7 +346,7 @@ func ConfigListDataAgreements(w http.ResponseWriter, r *http.Request) {
return
}
m := "Failed to paginate data agreement"
common.HandleErrorV2(w, http.StatusInternalServerError, m, err)
common.HandleErrorV2(w, http.StatusBadRequest, m, err)
return

}
Expand All @@ -362,7 +362,7 @@ func ConfigListDataAgreements(w http.ResponseWriter, r *http.Request) {
dataAgreements, err := getDataAgreementsWithRevisions(organisationId, lifecycle)
if err != nil {
m := "Failed to fetch data agreements"
common.HandleErrorV2(w, http.StatusInternalServerError, m, err)
common.HandleErrorV2(w, http.StatusBadRequest, m, err)
return
}

Expand All @@ -387,7 +387,7 @@ func ConfigListDataAgreements(w http.ResponseWriter, r *http.Request) {
dataAgreements, err := listDataAgreementsBasedOnLifecycle(lifecycle, organisationId)
if err != nil {
m := "Failed to fetch data agreements"
common.HandleErrorV2(w, http.StatusInternalServerError, m, err)
common.HandleErrorV2(w, http.StatusBadRequest, m, err)
return
}

Expand All @@ -412,15 +412,15 @@ func ConfigListDataAgreements(w http.ResponseWriter, r *http.Request) {
revisionResp, err := revision.GetByRevisionId(revisionId)
if err != nil {
m := fmt.Sprintf("Failed to fetch revision by id: %v", revisionId)
common.HandleErrorV2(w, http.StatusInternalServerError, m, err)
common.HandleErrorV2(w, http.StatusBadRequest, m, err)
return
}

// Recreate data agreement from revision
da, err := revision.RecreateDataAgreementFromRevision(revisionResp)
if err != nil {
m := fmt.Sprintf("Failed to fetch data agreement by revision: %v", revisionId)
common.HandleErrorV2(w, http.StatusInternalServerError, m, err)
common.HandleErrorV2(w, http.StatusBadRequest, m, err)
return
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func ConfigListDataAttributesForDataAgreement(w http.ResponseWriter, r *http.Req
da, err := daRepo.Get(dataAgreementId)
if err != nil {
m := fmt.Sprintf("Failed to fetch data agreement: %v", dataAgreementId)
common.HandleErrorV2(w, http.StatusInternalServerError, m, err)
common.HandleErrorV2(w, http.StatusBadRequest, m, err)
return
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func ConfigReadDataAgreement(w http.ResponseWriter, r *http.Request) {
da, err := daRepo.Get(dataAgreementId)
if err != nil {
m := fmt.Sprintf("Failed to fetch data agreement: %v", dataAgreementId)
common.HandleErrorV2(w, http.StatusInternalServerError, m, err)
common.HandleErrorV2(w, http.StatusBadRequest, m, err)
return
}

Expand All @@ -55,7 +55,7 @@ func ConfigReadDataAgreement(w http.ResponseWriter, r *http.Request) {
rev, err = revision.GetByRevisionId(revisionId)
if err != nil {
m := fmt.Sprintf("Failed to fetch revision: %v", dataAgreementId)
common.HandleErrorV2(w, http.StatusInternalServerError, m, err)
common.HandleErrorV2(w, http.StatusBadRequest, m, err)
return
}

Expand All @@ -67,7 +67,7 @@ func ConfigReadDataAgreement(w http.ResponseWriter, r *http.Request) {
rev, err = revision.GetLatestByDataAgreementId(dataAgreementId)
if err != nil {
m := fmt.Sprintf("Failed to fetch revision: %v", dataAgreementId)
common.HandleErrorV2(w, http.StatusInternalServerError, m, err)
common.HandleErrorV2(w, http.StatusBadRequest, m, err)
return
}

Expand All @@ -77,7 +77,7 @@ func ConfigReadDataAgreement(w http.ResponseWriter, r *http.Request) {
rev, err = revision.CreateRevisionForDraftDataAgreement(da, orgAdminId)
if err != nil {
m := "Failed to create revision in run time"
common.HandleErrorV2(w, http.StatusInternalServerError, m, err)
common.HandleErrorV2(w, http.StatusBadRequest, m, err)
return
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ func ConfigUpdateDataAgreement(w http.ResponseWriter, r *http.Request) {
o, err := org.Get(organisationId)
if err != nil {
m := fmt.Sprintf("Failed to get organization by ID :%v", organisationId)
common.HandleErrorV2(w, http.StatusNotFound, m, err)
common.HandleErrorV2(w, http.StatusBadRequest, m, err)
return
}

Expand All @@ -198,7 +198,7 @@ func ConfigUpdateDataAgreement(w http.ResponseWriter, r *http.Request) {
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)
common.HandleErrorV2(w, http.StatusBadRequest, m, err)
return
}
if count >= 1 {
Expand All @@ -213,7 +213,7 @@ func ConfigUpdateDataAgreement(w http.ResponseWriter, r *http.Request) {
currentDataAgreement, err := daRepo.Get(dataAgreementId)
if err != nil {
m := fmt.Sprintf("Failed to fetch data agreement by id: %v", dataAgreementId)
common.HandleErrorV2(w, http.StatusInternalServerError, m, err)
common.HandleErrorV2(w, http.StatusBadRequest, m, err)
return
}
currentVersion := currentDataAgreement.Version
Expand All @@ -226,7 +226,7 @@ func ConfigUpdateDataAgreement(w http.ResponseWriter, r *http.Request) {
updatedVersion, err := common.BumpMajorVersion(toBeUpdatedDataAgreement.Version)
if err != nil {
m := fmt.Sprintf("Failed to bump major version for data agreement: %v", dataAgreementId)
common.HandleErrorV2(w, http.StatusInternalServerError, m, err)
common.HandleErrorV2(w, http.StatusBadRequest, m, err)
return
}

Expand All @@ -249,7 +249,7 @@ func ConfigUpdateDataAgreement(w http.ResponseWriter, r *http.Request) {
newRevision, err = revision.UpdateRevisionForDataAgreement(toBeUpdatedDataAgreement, orgAdminId)
if err != nil {
m := fmt.Sprintf("Failed to update data agreement: %v", dataAgreementId)
common.HandleErrorV2(w, http.StatusInternalServerError, m, err)
common.HandleErrorV2(w, http.StatusBadRequest, m, err)
return
}

Expand All @@ -259,7 +259,7 @@ func ConfigUpdateDataAgreement(w http.ResponseWriter, r *http.Request) {
newRevision, err = revision.CreateRevisionForDraftDataAgreement(toBeUpdatedDataAgreement, orgAdminId)
if err != nil {
m := fmt.Sprintf("Failed to create revision for draft data agreement: %v", dataAgreementId)
common.HandleErrorV2(w, http.StatusInternalServerError, m, err)
common.HandleErrorV2(w, http.StatusBadRequest, m, err)
return
}
}
Expand All @@ -268,7 +268,7 @@ func ConfigUpdateDataAgreement(w http.ResponseWriter, r *http.Request) {
savedDataAgreement, err := daRepo.Update(toBeUpdatedDataAgreement)
if err != nil {
m := fmt.Sprintf("Failed to update data agreement: %v", toBeUpdatedDataAgreement.Id)
common.HandleErrorV2(w, http.StatusInternalServerError, m, err)
common.HandleErrorV2(w, http.StatusBadRequest, m, err)
return
}

Expand Down

0 comments on commit 68eb1b6

Please sign in to comment.