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

Method CreateBalanceMonitor

api/balance.go:204–224  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 4

ToBalanceMonitorMethod · 0.95
CreateMonitorMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected