UpdateMetadata handles HTTP requests to update metadata for various entity types. It processes requests to update metadata for ledgers, transactions, balances, and identities. The entity type is determined automatically from the entity ID prefix. Parameters: - c: The Gin context containing the requ
(c *gin.Context)
| 25 | // - 404 Not Found: If the specified entity doesn't exist. |
| 26 | // - 200 OK: If the metadata is successfully updated. |
| 27 | func (a Api) UpdateMetadata(c *gin.Context) { |
| 28 | entityID := c.Param("entity-id") |
| 29 | |
| 30 | if entityID == "" { |
| 31 | c.JSON(http.StatusBadRequest, gin.H{"error": "entity ID is required"}) |
| 32 | return |
| 33 | } |
| 34 | |
| 35 | var req MetadataRequest |
| 36 | if err := c.ShouldBindJSON(&req); err != nil { |
| 37 | c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) |
| 38 | return |
| 39 | } |
| 40 | |
| 41 | updatedMetadata, err := a.ledgerforge.UpdateMetadata(c.Request.Context(), entityID, req.Metadata) |
| 42 | if err != nil { |
| 43 | if errors.Is(err, errors.New("entity not found")) { |
| 44 | c.JSON(http.StatusNotFound, gin.H{"error": "entity not found"}) |
| 45 | return |
| 46 | } |
| 47 | c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) |
| 48 | return |
| 49 | } |
| 50 | |
| 51 | c.JSON(http.StatusOK, gin.H{"meta_data": updatedMetadata}) |
| 52 | } |