|
| 1 | +package rest |
| 2 | + |
| 3 | +import ( |
| 4 | + "dyn-https/blockchain/dynamic" |
| 5 | + "dyn-https/models" |
| 6 | + "encoding/json" |
| 7 | + "fmt" |
| 8 | + "io/ioutil" |
| 9 | + "net/http" |
| 10 | + |
| 11 | + "github.com/gin-gonic/gin" |
| 12 | +) |
| 13 | + |
| 14 | +func (w *WebProxy) addaudit(c *gin.Context) { |
| 15 | + body, err := ioutil.ReadAll(c.Request.Body) |
| 16 | + if err != nil { |
| 17 | + strErrMsg := fmt.Sprintf("Request body read all error %v", err) |
| 18 | + c.JSON(http.StatusBadRequest, gin.H{"error": strErrMsg}) |
| 19 | + return |
| 20 | + } |
| 21 | + if len(body) == 0 { |
| 22 | + c.JSON(http.StatusBadRequest, gin.H{"error": "Request body is empty"}) |
| 23 | + return |
| 24 | + } |
| 25 | + req := models.AuditAddRequest{} |
| 26 | + err = json.Unmarshal(body, &req) |
| 27 | + if err != nil { |
| 28 | + strErrMsg := fmt.Sprintf("Request body JSON unmarshal error %v", err) |
| 29 | + c.JSON(http.StatusBadRequest, gin.H{"error": strErrMsg}) |
| 30 | + return |
| 31 | + } |
| 32 | + //audit add "hash_array" ( "account" ) ( "description" ) ( "algorithm" ) |
| 33 | + cmd, _ := dynamic.NewRequest(`dynamic-cli audit add "` + req.HashArray + `" "` + req.Account + |
| 34 | + `"` + `" "` + req.Description + `"` + `" "` + req.Algorithm + `"`) |
| 35 | + response, _ := <-w.dynamicd.ExecCmdRequest(cmd) |
| 36 | + var result interface{} |
| 37 | + err = json.Unmarshal([]byte(response), &result) |
| 38 | + if err != nil { |
| 39 | + strErrMsg := fmt.Sprintf("Results JSON unmarshal error %v", err) |
| 40 | + c.JSON(http.StatusBadRequest, gin.H{"error": strErrMsg}) |
| 41 | + return |
| 42 | + } |
| 43 | + c.JSON(http.StatusOK, result) |
| 44 | +} |
| 45 | + |
| 46 | +func (w *WebProxy) getaudit(c *gin.Context) { |
| 47 | + Id := c.Param("UserID") |
| 48 | + cmd, _ := dynamic.NewRequest(`dynamic-cli audit get "` + Id + `"`) |
| 49 | + response, _ := <-w.dynamicd.ExecCmdRequest(cmd) |
| 50 | + var result interface{} |
| 51 | + err := json.Unmarshal([]byte(response), &result) |
| 52 | + if err != nil { |
| 53 | + strErrMsg := fmt.Sprintf("Results JSON unmarshal error %v", err) |
| 54 | + c.JSON(http.StatusBadRequest, gin.H{"error": strErrMsg}) |
| 55 | + return |
| 56 | + } |
| 57 | + c.JSON(http.StatusOK, result) |
| 58 | +} |
| 59 | + |
| 60 | +func (w *WebProxy) verifyaudit(c *gin.Context) { |
| 61 | + hash := c.Param("Hash") |
| 62 | + cmd, _ := dynamic.NewRequest(`dynamic-cli audit verify "` + hash + `"`) |
| 63 | + response, _ := <-w.dynamicd.ExecCmdRequest(cmd) |
| 64 | + var result interface{} |
| 65 | + err := json.Unmarshal([]byte(response), &result) |
| 66 | + if err != nil { |
| 67 | + strErrMsg := fmt.Sprintf("Results JSON unmarshal error %v", err) |
| 68 | + c.JSON(http.StatusBadRequest, gin.H{"error": strErrMsg}) |
| 69 | + return |
| 70 | + } |
| 71 | + c.JSON(http.StatusOK, result) |
| 72 | +} |
0 commit comments