@@ -134,37 +134,57 @@ func handleTransactionsRequest(c *gin.Context, contractAddress, signature string
134134 return
135135 }
136136
137- result , err := mainStorage .GetTransactions (storage.QueryFilter {
137+ // Prepare the QueryFilter
138+ qf := storage.QueryFilter {
138139 FilterParams : queryParams .FilterParams ,
139- GroupBy : queryParams .GroupBy ,
140+ ContractAddress : contractAddress ,
141+ Signature : signatureHash ,
142+ ChainId : chainId ,
140143 SortBy : queryParams .SortBy ,
141144 SortOrder : queryParams .SortOrder ,
142145 Page : queryParams .Page ,
143146 Limit : queryParams .Limit ,
144- Aggregates : queryParams .Aggregates ,
145- ContractAddress : contractAddress ,
146- Signature : signatureHash ,
147- ChainId : chainId ,
148- })
149- if err != nil {
150- log .Error ().Err (err ).Msg ("Error querying transactions" )
151- api .InternalErrorHandler (c )
152- return
153147 }
154148
155- response := api.QueryResponse {
149+ // Initialize the QueryResult
150+ queryResult := api.QueryResponse {
156151 Meta : api.Meta {
157152 ChainId : chainId .Uint64 (),
158153 ContractAddress : contractAddress ,
159- Signature : signature ,
154+ Signature : signatureHash ,
160155 Page : queryParams .Page ,
161156 Limit : queryParams .Limit ,
162- TotalItems : 0 , // TODO: Implement total items count
157+ TotalItems : 0 ,
163158 TotalPages : 0 , // TODO: Implement total pages count
164159 },
165- Data : result . Data ,
160+ Data : nil ,
166161 Aggregations : nil ,
167162 }
168163
169- c .JSON (http .StatusOK , response )
164+ // If aggregates or groupings are specified, retrieve them
165+ if len (queryParams .Aggregates ) > 0 || len (queryParams .GroupBy ) > 0 {
166+ qf .Aggregates = queryParams .Aggregates
167+ qf .GroupBy = queryParams .GroupBy
168+
169+ aggregatesResult , err := mainStorage .GetAggregations ("transactions" , qf )
170+ if err != nil {
171+ log .Error ().Err (err ).Msg ("Error querying aggregates" )
172+ api .InternalErrorHandler (c )
173+ return
174+ }
175+ queryResult .Aggregations = aggregatesResult .Aggregates
176+ queryResult .Meta .TotalItems = len (aggregatesResult .Aggregates )
177+ } else {
178+ // Retrieve logs data
179+ transactionsResult , err := mainStorage .GetTransactions (qf )
180+ if err != nil {
181+ log .Error ().Err (err ).Msg ("Error querying tran" )
182+ api .InternalErrorHandler (c )
183+ return
184+ }
185+ queryResult .Data = transactionsResult .Data
186+ queryResult .Meta .TotalItems = len (transactionsResult .Data )
187+ }
188+
189+ c .JSON (http .StatusOK , queryResult )
170190}
0 commit comments