webapi: New endpoint /profile/delete

This commit is contained in:
Kleissner
2021-09-20 14:20:23 +02:00
parent 680723faf3
commit 149984eeb3
3 changed files with 44 additions and 0 deletions

View File

@@ -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)

View File

@@ -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) {

View File

@@ -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
}]
}
```