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

Method CreateLedger

api/ledger.go:38–58  ·  view source on GitHub ↗

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

(c *gin.Context)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 4

ValidateCreateLedgerMethod · 0.95
ToLedgerMethod · 0.95
CreateLedgerMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected