CreateAccount handles the creation of a new account. It binds the incoming JSON request body to a CreateAccount model, validates it, and creates the account if the input is valid. Parameters: - c: The Gin context containing the request and response. Responses: - 400 Bad Request: If there's an erro
(c *gin.Context)
| 37 | // - 201 Created: If the account is successfully created. |
| 38 | // - 500 Internal Server Error: If there's an error in account creation. |
| 39 | func (a Api) CreateAccount(c *gin.Context) { |
| 40 | var newAccount model2.CreateAccount |
| 41 | if err := c.ShouldBindJSON(&newAccount); err != nil { |
| 42 | c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) |
| 43 | return |
| 44 | } |
| 45 | |
| 46 | err := newAccount.ValidateCreateAccount() |
| 47 | if err != nil { |
| 48 | c.JSON(http.StatusBadRequest, gin.H{"errors": err.Error()}) |
| 49 | return |
| 50 | } |
| 51 | |
| 52 | resp, err := a.ledgerforge.CreateAccount(newAccount.ToAccount()) |
| 53 | if err != nil { |
| 54 | c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) |
| 55 | return |
| 56 | } |
| 57 | c.JSON(http.StatusCreated, resp) |
| 58 | } |
| 59 | |
| 60 | // GetAccount retrieves an account by its ID. |
| 61 | // It uses the provided account ID and optional query parameters to fetch the account. |
nothing calls this directly
no test coverage detected