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

Method GetBalances

api/balance.go:110–151  ·  view source on GitHub ↗

GetBalances retrieves a list of balance records with pagination. It extracts the 'limit' and 'offset' query parameters to control pagination, and the 'include' query parameter to fetch additional related information. Supports advanced filtering via query parameters in the format: field_operator=valu

(c *gin.Context)

Source from the content-addressed store, hash-verified

108// - 400 Bad Request: If there's an error retrieving the balances or invalid query parameters.
109// - 200 OK: If the balances are successfully retrieved.
110func (a Api) GetBalances(c *gin.Context) {
111 // Extract pagination parameters (limit and offset)
112 limit, err := strconv.Atoi(c.DefaultQuery("limit", "10")) // Default to 10 if not specified
113 if err != nil || limit <= 0 {
114 c.JSON(http.StatusBadRequest, gin.H{"error": "invalid limit value"})
115 return
116 }
117
118 offset, err := strconv.Atoi(c.DefaultQuery("offset", "0")) // Default to 0 if not specified
119 if err != nil || offset < 0 {
120 c.JSON(http.StatusBadRequest, gin.H{"error": "invalid offset value"})
121 return
122 }
123
124 // Check if advanced filters are present
125 if HasFilters(c) {
126 filters, parseErrors := ParseFiltersFromContext(c, nil)
127 if len(parseErrors) > 0 {
128 c.JSON(http.StatusBadRequest, gin.H{"errors": parseErrors})
129 return
130 }
131
132 // Use the new filter method
133 resp, err := a.ledgerforge.GetAllBalancesWithFilter(c.Request.Context(), filters, limit, offset)
134 if err != nil {
135 c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
136 return
137 }
138
139 c.JSON(http.StatusOK, resp)
140 return
141 }
142
143 // Fetch balances with pagination
144 resp, err := a.ledgerforge.GetAllBalances(c.Request.Context(), limit, offset)
145 if err != nil {
146 c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
147 return
148 }
149
150 c.JSON(http.StatusOK, resp)
151}
152
153// FilterBalances filters balances using a JSON request body.
154// This endpoint accepts a POST request with filters specified in JSON format.

Callers

nothing calls this directly

Calls 5

HasFiltersFunction · 0.85
ParseFiltersFromContextFunction · 0.85
GetAllBalancesMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected