add fundraising API

This commit is contained in:
Pierre de Lacroix 2026-01-22 19:35:01 +01:00
parent d2ec7b12a9
commit 4aad4d1251
Signed by: lateralus23
GPG key ID: 53E0CEC29C24EF39
3 changed files with 18 additions and 0 deletions

View file

@ -3,6 +3,7 @@ defmodule CampApiWeb.GristController do
alias CampApi.Grist
alias CampApi.Grist.Gauge
alias CampApi.Grist.Fundraising
action_fallback CampApiWeb.FallbackController
@ -11,4 +12,10 @@ defmodule CampApiWeb.GristController do
render(conn, :gauge, gauge: gauge)
end
def fundraising(conn, _params) do
fundraising = Fundraising.get()
render(conn, :fundraising, fundraising: fundraising)
end
end

View file

@ -4,4 +4,13 @@ defmodule CampApiWeb.GristJSON do
def gauge(%{gauge: gauge}) do
%{gauge: gauge}
end
def fundraising(%{fundraising: fundraising}) do
total =
fundraising
|> Enum.map(fn record -> get_in(record, ["fields", "Montant"]) end)
|> Enum.sum()
%{total: total}
end
end

View file

@ -9,6 +9,8 @@ defmodule CampApiWeb.Router do
pipe_through :api
get "/gauge", GristController, :gauge
get "/fundraising", GristController, :fundraising
end
# Enable LiveDashboard in development