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)
| 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. |
| 40 | func (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 |
nothing calls this directly
no test coverage detected