mirror of
https://github.com/GrassrootsEconomics/cic-dw.git
synced 2026-05-27 23:17:55 +02:00
fix: move latest tx to dashboard domain
This commit is contained in:
@@ -28,4 +28,5 @@ func InitDashboardApi(e *echo.Echo, db *pgxpool.Pool, queries goyesql.Queries) {
|
||||
g.GET("/transactions-count", handleTransactionsCount)
|
||||
g.GET("/token-transactions-count/:address", handleTokenTransactionsCount)
|
||||
g.GET("/token-volume/:address", handleTokenVolume)
|
||||
g.GET("/latest-token-transactions/:address", handleLatestTokenTransactions)
|
||||
}
|
||||
|
||||
@@ -1,14 +1,12 @@
|
||||
package public
|
||||
package dashboard
|
||||
|
||||
import (
|
||||
"cic-dw/pkg/pagination"
|
||||
"context"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/georgysavva/scany/pgxscan"
|
||||
"github.com/labstack/echo/v4"
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
type tokenTransactionsRes struct {
|
||||
@@ -22,27 +20,15 @@ type tokenTransactionsRes struct {
|
||||
Success bool `db:"success" json:"success"`
|
||||
}
|
||||
|
||||
func handleTokenTransactions(c echo.Context) error {
|
||||
func handleLatestTokenTransactions(c echo.Context) error {
|
||||
var (
|
||||
api = c.Get("api").(*api)
|
||||
token = c.Param("address")
|
||||
pg = pagination.GetPagination(c.QueryParams())
|
||||
|
||||
data []tokenTransactionsRes
|
||||
)
|
||||
|
||||
if pg.Cursor == -1 {
|
||||
var max int64
|
||||
if err := api.db.QueryRow(context.Background(), "SELECT MAX(id) + 10 from transactions").Scan(&max); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
pg.Cursor = int(max)
|
||||
}
|
||||
|
||||
log.Info().Msgf("%d", pg.Cursor)
|
||||
|
||||
rows, err := api.db.Query(context.Background(), api.q["latest-token-transactions"], token, pg.Cursor, pg.PerPage)
|
||||
rows, err := api.db.Query(context.Background(), api.q["latest-token-transactions"], token)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -51,5 +37,9 @@ func handleTokenTransactions(c echo.Context) error {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(data) < 1 {
|
||||
data = []tokenTransactionsRes{}
|
||||
}
|
||||
|
||||
return c.JSON(http.StatusOK, data)
|
||||
}
|
||||
@@ -37,5 +37,4 @@ func InitPublicApi(e *echo.Echo, db *pgxpool.Pool, batchBalance *batch_balance.B
|
||||
g.GET("/tokens", handleTokenListQuery)
|
||||
g.GET("/token/:address", handleTokenInfo)
|
||||
g.GET("/token-summary/:address", handleTokenSummary)
|
||||
g.GET("/latest-token-transactions/:address", handleTokenTransactions)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user