diff --git a/webapi/API.go b/webapi/API.go index 3467986..4d292c6 100644 --- a/webapi/API.go +++ b/webapi/API.go @@ -51,6 +51,7 @@ func Start(ListenAddresses []string, UseSSL bool, CertificateFile, CertificateKe Router.HandleFunc("/profile/list", apiProfileList).Methods("GET") Router.HandleFunc("/profile/read", apiProfileRead).Methods("GET") Router.HandleFunc("/profile/write", apiProfileWrite).Methods("POST") + Router.HandleFunc("/profile/delete", apiProfileDelete).Methods("POST") for _, listen := range ListenAddresses { go startWebServer(listen, UseSSL, CertificateFile, CertificateKey, Router, "API", TimeoutRead, TimeoutWrite) diff --git a/webapi/Profile.go b/webapi/Profile.go index b466c03..607562f 100644 --- a/webapi/Profile.go +++ b/webapi/Profile.go @@ -101,6 +101,33 @@ func apiProfileWrite(w http.ResponseWriter, r *http.Request) { EncodeJSON(w, r, apiBlockchainBlockStatus{Status: status, Height: newHeight, Version: newVersion}) } +/* +apiProfileDelete deletes profile fields or blobs identified by the types. +For the index see core.ProfileFieldX and core.ProfileBlobX constants. + +Request: POST /profile/delete with JSON structure apiProfileData +Response: 200 with JSON structure apiBlockchainBlockStatus +*/ +func apiProfileDelete(w http.ResponseWriter, r *http.Request) { + var input apiProfileData + if err := DecodeJSON(w, r, &input); err != nil { + return + } + + var fields, blobs []uint16 + + for n := range input.Fields { + fields = append(fields, input.Fields[n].Type) + } + for n := range input.Blobs { + blobs = append(blobs, input.Blobs[n].Type) + } + + newHeight, newVersion, status := core.UserProfileDelete(fields, blobs) + + EncodeJSON(w, r, apiBlockchainBlockStatus{Status: status, Height: newHeight, Version: newVersion}) +} + // --- conversion from core to API data --- func blockRecordProfileToAPI(input core.BlockRecordProfile) (output apiBlockRecordProfile) { diff --git a/webapi/readme.md b/webapi/readme.md index e62000b..f847d36 100644 --- a/webapi/readme.md +++ b/webapi/readme.md @@ -439,3 +439,19 @@ Example response: } ``` +### Profile Delete + +``` +Request: POST /profile/delete with JSON structure apiProfileData +Response: 200 with JSON structure apiBlockchainBlockStatus +``` + +Example POST request to `http://127.0.0.1:112/profile/delete`: + +```json +{ + "fields": [{ + "type": 0 + }] +} +```