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

Method GetAllLedgers

api/ledger.go:104–149  ·  view source on GitHub ↗

GetAllLedgers retrieves all ledger records in the system. It fetches the ledger records and responds with the list of ledgers. Supports advanced filtering via query parameters in the format: field_operator=value Example filters: - name_eq=USD Ledger - created_at_gte=2024-01-01 - name_ilike=%savings%

(c *gin.Context)

Source from the content-addressed store, hash-verified

102// - 400 Bad Request: If there's an error retrieving the ledger records or invalid filters.
103// - 200 OK: If the ledger records are successfully retrieved.
104func (a Api) GetAllLedgers(c *gin.Context) {
105 // Extract limit and offset from query parameters
106 limit := c.DefaultQuery("limit", "10") // Default limit is 10 if not provided
107 offset := c.DefaultQuery("offset", "0") // Default offset is 0 if not provided
108
109 // Convert limit and offset to integers
110 limitInt, err := strconv.Atoi(limit)
111 if err != nil || limitInt < 1 {
112 c.JSON(http.StatusBadRequest, gin.H{"error": "Invalid limit value"})
113 return
114 }
115
116 offsetInt, err := strconv.Atoi(offset)
117 if err != nil || offsetInt < 0 {
118 c.JSON(http.StatusBadRequest, gin.H{"error": "Invalid offset value"})
119 return
120 }
121
122 // Check if advanced filters are present
123 if HasFilters(c) {
124 filters, parseErrors := ParseFiltersFromContext(c, nil)
125 if len(parseErrors) > 0 {
126 c.JSON(http.StatusBadRequest, gin.H{"errors": parseErrors})
127 return
128 }
129
130 // Use the new filter method
131 resp, err := a.ledgerforge.GetAllLedgersWithFilter(c.Request.Context(), filters, limitInt, offsetInt)
132 if err != nil {
133 c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
134 return
135 }
136
137 c.JSON(http.StatusOK, resp)
138 return
139 }
140
141 // Fall back to the legacy method when no filters are present
142 resp, err := a.ledgerforge.GetAllLedgers(limitInt, offsetInt)
143 if err != nil {
144 c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
145 return
146 }
147
148 c.JSON(http.StatusOK, resp)
149}
150
151// FilterLedgers filters ledgers using a JSON request body.
152// 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
GetAllLedgersMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected