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

Method CreateBalance

api/balance.go:40–60  ·  view source on GitHub ↗

CreateBalance creates a new balance record in the system. It binds the incoming JSON request to a CreateBalance object, validates it, and then creates the balance record. If any errors occur during validation or creation, it responds with an appropriate error message. Parameters: - c: The Gin conte

(c *gin.Context)

Source from the content-addressed store, hash-verified

38// - 400 Bad Request: If there's an error in binding JSON or validating the balance.
39// - 201 Created: If the balance is successfully created.
40func (a Api) CreateBalance(c *gin.Context) {
41 var newBalance model2.CreateBalance
42 if err := c.ShouldBindJSON(&newBalance); err != nil {
43 c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
44 return
45 }
46
47 err := newBalance.ValidateCreateBalance()
48 if err != nil {
49 c.JSON(http.StatusBadRequest, gin.H{"errors": err.Error()})
50 return
51 }
52
53 resp, err := a.ledgerforge.CreateBalance(c.Request.Context(), newBalance.ToBalance())
54 if err != nil {
55 c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
56 return
57 }
58
59 c.JSON(http.StatusCreated, resp)
60}
61
62// GetBalance retrieves a balance record by its ID.
63// It extracts the ID from the route parameters and the 'include' query

Callers

nothing calls this directly

Calls 4

ValidateCreateBalanceMethod · 0.95
ToBalanceMethod · 0.95
CreateBalanceMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected