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

Method CreateAccount

api/accounts.go:39–58  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

37// - 201 Created: If the account is successfully created.
38// - 500 Internal Server Error: If there's an error in account creation.
39func (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.

Callers

nothing calls this directly

Calls 4

ValidateCreateAccountMethod · 0.95
ToAccountMethod · 0.95
CreateAccountMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected