CreateBalanceMonitor creates a new balance monitor record in the system. It binds the incoming JSON request to a CreateBalanceMonitor object, validates it, and then creates the monitor record. If any errors occur during validation or creation, it responds with an appropriate error message. Paramete
(c *gin.Context)
| 202 | // - 400 Bad Request: If there's an error in binding JSON or validating the balance monitor. |
| 203 | // - 201 Created: If the balance monitor is successfully created. |
| 204 | func (a Api) CreateBalanceMonitor(c *gin.Context) { |
| 205 | var newMonitor model2.CreateBalanceMonitor |
| 206 | if err := c.ShouldBindJSON(&newMonitor); err != nil { |
| 207 | c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) |
| 208 | return |
| 209 | } |
| 210 | |
| 211 | err := newMonitor.ValidateCreateBalanceMonitor() |
| 212 | if err != nil { |
| 213 | c.JSON(http.StatusBadRequest, gin.H{"errors": err.Error()}) |
| 214 | return |
| 215 | } |
| 216 | |
| 217 | resp, err := a.ledgerforge.CreateMonitor(c.Request.Context(), newMonitor.ToBalanceMonitor()) |
| 218 | if err != nil { |
| 219 | c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) |
| 220 | return |
| 221 | } |
| 222 | |
| 223 | c.JSON(http.StatusCreated, resp) |
| 224 | } |
| 225 | |
| 226 | // GetBalanceMonitor retrieves a balance monitor record by its ID. |
| 227 | // It extracts the ID from the route parameters. If the ID is missing |
nothing calls this directly
no test coverage detected