MCPcopy Create free account
hub / github.com/devaccuracy/ledgerforge / UpdateIdentity

Method UpdateIdentity

api/identity.go:93–114  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.
93func (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

Callers

nothing calls this directly

Calls 3

GetMethod · 0.65
UpdateIdentityMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected