2022-05-11 15:57:56 +02:00
|
|
|
package dashboard
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"net/http"
|
|
|
|
"time"
|
2022-05-23 14:41:24 +02:00
|
|
|
|
|
|
|
"github.com/georgysavva/scany/pgxscan"
|
|
|
|
"github.com/labstack/echo/v4"
|
2022-05-11 15:57:56 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
type lineChartRes struct {
|
|
|
|
X time.Time `db:"x" json:"x"`
|
|
|
|
Y int `db:"y" json:"y"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func handleNewRegistrations(c echo.Context) error {
|
|
|
|
var (
|
2022-05-23 14:41:24 +02:00
|
|
|
api = c.Get("api").(*api)
|
|
|
|
|
2022-05-11 15:57:56 +02:00
|
|
|
data []lineChartRes
|
|
|
|
)
|
|
|
|
|
|
|
|
from, to := parseDateRange(c.QueryParams())
|
|
|
|
|
|
|
|
rows, err := api.db.Query(context.Background(), api.q["new-user-registrations"], from, to)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := pgxscan.ScanAll(&data, rows); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return c.JSON(http.StatusOK, data)
|
|
|
|
}
|
|
|
|
|
|
|
|
func handleTransactionsCount(c echo.Context) error {
|
|
|
|
var (
|
2022-05-23 14:41:24 +02:00
|
|
|
api = c.Get("api").(*api)
|
|
|
|
|
2022-05-11 15:57:56 +02:00
|
|
|
data []lineChartRes
|
|
|
|
)
|
|
|
|
|
|
|
|
from, to := parseDateRange(c.QueryParams())
|
|
|
|
|
|
|
|
rows, err := api.db.Query(context.Background(), api.q["transactions-count"], from, to)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := pgxscan.ScanAll(&data, rows); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return c.JSON(http.StatusOK, data)
|
|
|
|
}
|
2022-05-23 14:41:24 +02:00
|
|
|
|
|
|
|
func handleTokenTransactionsCount(c echo.Context) error {
|
|
|
|
var (
|
|
|
|
api = c.Get("api").(*api)
|
|
|
|
token = c.Param("address")
|
|
|
|
|
|
|
|
data []lineChartRes
|
|
|
|
)
|
|
|
|
|
|
|
|
from, to := parseDateRange(c.QueryParams())
|
|
|
|
|
|
|
|
rows, err := api.db.Query(context.Background(), api.q["token-transactions-count"], from, to, token)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := pgxscan.ScanAll(&data, rows); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return c.JSON(http.StatusOK, data)
|
|
|
|
}
|
|
|
|
|
|
|
|
func handleTokenVolume(c echo.Context) error {
|
|
|
|
var (
|
|
|
|
api = c.Get("api").(*api)
|
|
|
|
token = c.Param("address")
|
|
|
|
|
|
|
|
data []lineChartRes
|
|
|
|
)
|
|
|
|
|
|
|
|
from, to := parseDateRange(c.QueryParams())
|
|
|
|
|
|
|
|
rows, err := api.db.Query(context.Background(), api.q["token-volume"], from, to, token)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := pgxscan.ScanAll(&data, rows); err != nil {
|
|
|
|
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return c.JSON(http.StatusOK, data)
|
|
|
|
}
|