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

Method RecordTransaction

api/transactions.go:113–137  ·  view source on GitHub ↗

RecordTransaction handles the recording of a new transaction. It binds the incoming JSON request to a RecordTransaction object, validates it, and then records the transaction. If any errors occur during validation or recording, it responds with an appropriate error message. Parameters: - c: The Gin

(c *gin.Context)

Source from the content-addressed store, hash-verified

111// - 400 Bad Request: If there's an error in binding JSON or validating the transaction.
112// - 201 Created: If the transaction is successfully recorded.
113func (a Api) RecordTransaction(c *gin.Context) {
114 var newTransaction model2.RecordTransaction
115 // Bind the incoming JSON request to the newTransaction model
116 if err := c.ShouldBindJSON(&newTransaction); err != nil {
117 c.JSON(http.StatusBadRequest, gin.H{"errors": err.Error()})
118 return
119 }
120
121 // Validate the transaction data
122 err := newTransaction.ValidateRecordTransaction()
123 if err != nil {
124 handleRecordTransactionValidationError(c, err)
125 return
126 }
127
128 // Record the transaction using the LedgerForge service
129 resp, err := a.ledgerforge.RecordTransaction(c.Request.Context(), newTransaction.ToTransaction())
130 if err != nil {
131 c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
132 return
133 }
134
135 // Return a response with the recorded transaction, properly transformed
136 c.JSON(http.StatusCreated, transformTransaction(resp))
137}
138
139// QueueTransaction handles queuing a new transaction for later processing.
140// It binds the incoming JSON request to a RecordTransaction object, validates it,

Callers

nothing calls this directly

Calls 6

ToTransactionMethod · 0.95
transformTransactionFunction · 0.85
RecordTransactionMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected