Compare commits
2 commits
e1a6b72c44
...
4aad4d1251
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4aad4d1251 | ||
|
|
d2ec7b12a9 |
6 changed files with 26 additions and 4 deletions
|
|
@ -29,8 +29,7 @@ config :logger, :default_formatter,
|
|||
# Use Jason for JSON parsing in Phoenix
|
||||
config :phoenix, :json_library, Jason
|
||||
|
||||
config :camp_api, :grist,
|
||||
api_key: System.get_env("GRIST_API_KEY")
|
||||
config :camp_api, :grist, api_key: System.get_env("GRIST_API_KEY")
|
||||
|
||||
# Import environment specific config. This must remain at the bottom
|
||||
# of this file so it overrides the configuration defined above.
|
||||
|
|
|
|||
|
|
@ -10,6 +10,12 @@ defmodule CampApi.Grist do
|
|||
end
|
||||
|
||||
defp request(method, url) do
|
||||
Req.request(method: method, url: url, headers: [{"authorization", "Bearer " <> Application.fetch_env!(:camp_api, :grist)[:api_key]}])
|
||||
Req.request(
|
||||
method: method,
|
||||
url: url,
|
||||
headers: [
|
||||
{"authorization", "Bearer " <> Application.fetch_env!(:camp_api, :grist)[:api_key]}
|
||||
]
|
||||
)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@ defmodule CampApi.Grist.Gauge do
|
|||
|
||||
alias CampApi.Grist
|
||||
|
||||
|
||||
@gauge_doc "wpwHRjzfdR9A"
|
||||
@gauge_table "Infos"
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -9,6 +9,8 @@ defmodule CampApiWeb.Router do
|
|||
pipe_through :api
|
||||
|
||||
get "/gauge", GristController, :gauge
|
||||
|
||||
get "/fundraising", GristController, :fundraising
|
||||
end
|
||||
|
||||
# Enable LiveDashboard in development
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue