add fundraising API
This commit is contained in:
parent
d2ec7b12a9
commit
c95d877e68
4 changed files with 32 additions and 0 deletions
14
lib/camp_api/grist/fundraising.ex
Normal file
14
lib/camp_api/grist/fundraising.ex
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
defmodule CampApi.Grist.Fundraising do
|
||||||
|
@moduledoc false
|
||||||
|
|
||||||
|
alias CampApi.Grist
|
||||||
|
|
||||||
|
@gauge_doc "wWacvVWE9QtQ"
|
||||||
|
@gauge_table "Dons"
|
||||||
|
|
||||||
|
def get() do
|
||||||
|
{:ok, %{body: %{"records" => records}}} = Grist.get_records(@gauge_doc, @gauge_table)
|
||||||
|
|
||||||
|
records
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
@ -3,6 +3,7 @@ defmodule CampApiWeb.GristController do
|
||||||
|
|
||||||
alias CampApi.Grist
|
alias CampApi.Grist
|
||||||
alias CampApi.Grist.Gauge
|
alias CampApi.Grist.Gauge
|
||||||
|
alias CampApi.Grist.Fundraising
|
||||||
|
|
||||||
action_fallback CampApiWeb.FallbackController
|
action_fallback CampApiWeb.FallbackController
|
||||||
|
|
||||||
|
|
@ -11,4 +12,10 @@ defmodule CampApiWeb.GristController do
|
||||||
|
|
||||||
render(conn, :gauge, gauge: gauge)
|
render(conn, :gauge, gauge: gauge)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def fundraising(conn, _params) do
|
||||||
|
fundraising = Fundraising.get()
|
||||||
|
|
||||||
|
render(conn, :fundraising, fundraising: fundraising)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -4,4 +4,13 @@ defmodule CampApiWeb.GristJSON do
|
||||||
def gauge(%{gauge: gauge}) do
|
def gauge(%{gauge: gauge}) do
|
||||||
%{gauge: gauge}
|
%{gauge: gauge}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def fundraising(%{fundraising: fundraising}) do
|
||||||
|
total =
|
||||||
|
fundraising
|
||||||
|
|> Enum.map(fn record -> get_in(record, ["fields", "Montant"]) end)
|
||||||
|
|> Enum.sum()
|
||||||
|
|
||||||
|
%{total: total}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,8 @@ defmodule CampApiWeb.Router do
|
||||||
pipe_through :api
|
pipe_through :api
|
||||||
|
|
||||||
get "/gauge", GristController, :gauge
|
get "/gauge", GristController, :gauge
|
||||||
|
|
||||||
|
get "/fundraising", GristController, :fundraising
|
||||||
end
|
end
|
||||||
|
|
||||||
# Enable LiveDashboard in development
|
# Enable LiveDashboard in development
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue