UpdateBalanceMonitor updates an existing balance monitor record by its ID. It binds the incoming JSON request to a BalanceMonitor 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.
(c *gin.Context)
| 307 | // - 400 Bad Request: If there's an error in binding JSON, validating the balance monitor, or updating the record. |
| 308 | // - 200 OK: If the balance monitor is successfully updated. |
| 309 | func (a Api) UpdateBalanceMonitor(c *gin.Context) { |
| 310 | var monitor model.BalanceMonitor |
| 311 | id, passed := c.Params.Get("id") |
| 312 | if !passed { |
| 313 | c.JSON(http.StatusBadRequest, gin.H{"error": "id is required. pass id in the route /:id"}) |
| 314 | return |
| 315 | } |
| 316 | |
| 317 | if err := c.ShouldBindJSON(&monitor); err != nil { |
| 318 | c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) |
| 319 | return |
| 320 | } |
| 321 | |
| 322 | monitor.MonitorID = id |
| 323 | err := a.ledgerforge.UpdateMonitor(c.Request.Context(), &monitor) |
| 324 | if err != nil { |
| 325 | c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) |
| 326 | return |
| 327 | } |
| 328 | |
| 329 | c.JSON(http.StatusOK, gin.H{"message": "BalanceMonitor updated successfully"}) |
| 330 | } |
| 331 | |
| 332 | // DeleteBalanceMonitor deletes an existing balance monitor record by its ID. |
| 333 | // 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