mirror of
https://github.com/PeernetOfficial/core.git
synced 2026-07-22 12:47:51 +01:00
webapi: New endpoint /profile/delete
This commit is contained in:
@@ -51,6 +51,7 @@ func Start(ListenAddresses []string, UseSSL bool, CertificateFile, CertificateKe
|
|||||||
Router.HandleFunc("/profile/list", apiProfileList).Methods("GET")
|
Router.HandleFunc("/profile/list", apiProfileList).Methods("GET")
|
||||||
Router.HandleFunc("/profile/read", apiProfileRead).Methods("GET")
|
Router.HandleFunc("/profile/read", apiProfileRead).Methods("GET")
|
||||||
Router.HandleFunc("/profile/write", apiProfileWrite).Methods("POST")
|
Router.HandleFunc("/profile/write", apiProfileWrite).Methods("POST")
|
||||||
|
Router.HandleFunc("/profile/delete", apiProfileDelete).Methods("POST")
|
||||||
|
|
||||||
for _, listen := range ListenAddresses {
|
for _, listen := range ListenAddresses {
|
||||||
go startWebServer(listen, UseSSL, CertificateFile, CertificateKey, Router, "API", TimeoutRead, TimeoutWrite)
|
go startWebServer(listen, UseSSL, CertificateFile, CertificateKey, Router, "API", TimeoutRead, TimeoutWrite)
|
||||||
|
|||||||
@@ -101,6 +101,33 @@ func apiProfileWrite(w http.ResponseWriter, r *http.Request) {
|
|||||||
EncodeJSON(w, r, apiBlockchainBlockStatus{Status: status, Height: newHeight, Version: newVersion})
|
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 ---
|
// --- conversion from core to API data ---
|
||||||
|
|
||||||
func blockRecordProfileToAPI(input core.BlockRecordProfile) (output apiBlockRecordProfile) {
|
func blockRecordProfileToAPI(input core.BlockRecordProfile) (output apiBlockRecordProfile) {
|
||||||
|
|||||||
@@ -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
|
||||||
|
}]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|||||||
Reference in New Issue
Block a user