mirror of
https://github.com/GrassrootsEconomics/cic-dw.git
synced 2026-05-20 12:51:09 +02:00
patch: cameroon specific dashboard queries
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/georgysavva/scany/pgxscan"
|
||||
"github.com/jackc/pgx/v4"
|
||||
"github.com/labstack/echo/v4"
|
||||
)
|
||||
|
||||
@@ -18,15 +19,25 @@ type lineChartRes struct {
|
||||
func handleNewRegistrations(c echo.Context) error {
|
||||
var (
|
||||
api = c.Get("api").(*api)
|
||||
qP = c.QueryParams()
|
||||
|
||||
rows pgx.Rows
|
||||
err error
|
||||
data []lineChartRes
|
||||
)
|
||||
|
||||
from, to := date_range.ParseDateRange(c.QueryParams())
|
||||
from, to := date_range.ParseDateRange(qP)
|
||||
|
||||
rows, err := api.db.Query(context.Background(), api.q["new-user-registrations"], from, to)
|
||||
if err != nil {
|
||||
return err
|
||||
if qP.Get("country") == "cmr" {
|
||||
rows, err = api.db.Query(context.Background(), api.q["new-user-registrations-cmr"], from, to)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
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 {
|
||||
@@ -39,15 +50,25 @@ func handleNewRegistrations(c echo.Context) error {
|
||||
func handleTransactionsCount(c echo.Context) error {
|
||||
var (
|
||||
api = c.Get("api").(*api)
|
||||
qP = c.QueryParams()
|
||||
|
||||
rows pgx.Rows
|
||||
err error
|
||||
data []lineChartRes
|
||||
)
|
||||
|
||||
from, to := date_range.ParseDateRange(c.QueryParams())
|
||||
from, to := date_range.ParseDateRange(qP)
|
||||
|
||||
rows, err := api.db.Query(context.Background(), api.q["transactions-count"], from, to)
|
||||
if err != nil {
|
||||
return err
|
||||
if qP.Get("country") == "cmr" {
|
||||
rows, err = api.db.Query(context.Background(), api.q["transactions-count-cmr"], from, to)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
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 {
|
||||
|
||||
Reference in New Issue
Block a user