UpdateIdentity updates an existing identity record by its ID. It binds the incoming JSON request to an Identity object, updates the record, and responds with a success message. If any errors occur during binding, validation, or update, it responds with an appropriate error message. Parameters: - c:
(c *gin.Context)
| 91 | // - 400 Bad Request: If there's an error in binding JSON, updating the identity, or missing ID. |
| 92 | // - 200 OK: If the identity is successfully updated. |
| 93 | func (a Api) UpdateIdentity(c *gin.Context) { |
| 94 | var identity model.Identity |
| 95 | id, passed := c.Params.Get("id") |
| 96 | if !passed { |
| 97 | c.JSON(http.StatusBadRequest, gin.H{"error": "id is required. pass id in the route /:id"}) |
| 98 | return |
| 99 | } |
| 100 | |
| 101 | if err := c.ShouldBindJSON(&identity); err != nil { |
| 102 | c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) |
| 103 | return |
| 104 | } |
| 105 | |
| 106 | identity.IdentityID = id |
| 107 | err := a.ledgerforge.UpdateIdentity(&identity) |
| 108 | if err != nil { |
| 109 | c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) |
| 110 | return |
| 111 | } |
| 112 | |
| 113 | c.JSON(http.StatusOK, gin.H{"message": "Identity updated successfully"}) |
| 114 | } |
| 115 | |
| 116 | // DeleteIdentity deletes an existing identity record by its ID. |
| 117 | // It extracts the ID from the route parameters and deletes the record. If the ID is missing |
nothing calls this directly
no test coverage detected