Skip to content

Commit

Permalink
address PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
vmilitaru committed Mar 31, 2023
1 parent ed00001 commit 3df247b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion dataset/get-metadata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func TestUnitHandlers(t *testing.T) {
if collectionID == mockCollectionId {
return mockCollection, nil
} else {
return c, errors.New("Collection not found")
return c, errors.New("collection not found")
}
},
}
Expand Down
16 changes: 11 additions & 5 deletions dataset/put-metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package dataset

import (
"encoding/json"
"io"
"io/ioutil"
"net/http"

Expand Down Expand Up @@ -100,15 +101,15 @@ func putMetadata(w http.ResponseWriter, req *http.Request, dc DatasetClient, zc
}

// PutEditableMetadata updates a given list of metadata fields, agreed as being editable for both a dataset and a version object
// This new endpoint makes an unique call to the dataset api updating only the relevant metadata fields in a transactional way
// This new endpoint makes a unique call to the dataset api updating only the relevant metadata fields in a transactional way
// It also calls zebedee to update the collection
func PutEditableMetadata(dc DatasetClient, zc ZebedeeClient) http.HandlerFunc {
return dphandlers.ControllerHandler(func(w http.ResponseWriter, r *http.Request, lang, collectionID, accessToken string) {
putEditableMetadata(w, r, dc, zc, accessToken, collectionID, lang)
putEditableMetadata(w, r, dc, zc, accessToken, collectionID)
})
}

func putEditableMetadata(w http.ResponseWriter, req *http.Request, dc DatasetClient, zc ZebedeeClient, userAccessToken, collectionID, lang string) {
func putEditableMetadata(w http.ResponseWriter, req *http.Request, dc DatasetClient, zc ZebedeeClient, userAccessToken, collectionID string) {
ctx := req.Context()

err := checkAccessTokenAndCollectionHeaders(userAccessToken, collectionID)
Expand All @@ -129,7 +130,7 @@ func putEditableMetadata(w http.ResponseWriter, req *http.Request, dc DatasetCli
"version": version,
}

b, err := ioutil.ReadAll(req.Body)
b, err := io.ReadAll(req.Body)
if err != nil {
log.Error(ctx, "putMetadata endpoint: error reading body", err, log.Data(logInfo))
http.Error(w, "error reading body", http.StatusBadRequest)
Expand Down Expand Up @@ -165,10 +166,15 @@ func putEditableMetadata(w http.ResponseWriter, req *http.Request, dc DatasetCli
if err != nil {
log.Error(ctx, "error adding version to collection", err, log.Data(logInfo))
http.Error(w, "error adding version to collection", http.StatusInternalServerError)
return
}

w.WriteHeader(http.StatusOK)
w.Write(b)
if _, err = w.Write(b); err != nil {
log.Error(ctx, "failed to write response body", err, log.Data(logInfo))
http.Error(w, "failed to write response body", http.StatusInternalServerError)
return
}

log.Info(ctx, "put metadata: request successful", log.Data(logInfo))
}

0 comments on commit 3df247b

Please sign in to comment.