From fa38b226103ef5b2c9289b0dda80e8fb95f28419 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Lobo?= Date: Sat, 4 Nov 2023 20:52:28 +0000 Subject: [PATCH 1/2] feat: add wheel price endpoint --- lib/safira_web/controllers/roulette_controller.ex | 5 +++++ lib/safira_web/router.ex | 1 + lib/safira_web/views/roulette_view.ex | 4 ++++ 3 files changed, 10 insertions(+) diff --git a/lib/safira_web/controllers/roulette_controller.ex b/lib/safira_web/controllers/roulette_controller.ex index f073b011..11feb635 100644 --- a/lib/safira_web/controllers/roulette_controller.ex +++ b/lib/safira_web/controllers/roulette_controller.ex @@ -30,4 +30,9 @@ defmodule SafiraWeb.RouletteController do latest_prizes = Roulette.latest_five_wins() render(conn, "latest_prizes.json", latest_prizes: latest_prizes) end + + def price(conn, _params) do + price = Application.fetch_env!(:safira, :roulette_cost) + render(conn, "price.json", price: price) + end end diff --git a/lib/safira_web/router.ex b/lib/safira_web/router.ex index 92582053..4c96d26d 100644 --- a/lib/safira_web/router.ex +++ b/lib/safira_web/router.ex @@ -53,6 +53,7 @@ defmodule SafiraWeb.Router do get "/leaderboard", LeaderboardController, :index get "/leaderboard/:date", LeaderboardController, :daily get "/roulette/latestwins", RouletteController, :latest_wins + get "/roulette/price", RouletteController, :price get "/store/redeem/:id", DeliverRedeemableController, :show get "/roulette/redeem/:id", DeliverPrizeController, :show diff --git a/lib/safira_web/views/roulette_view.ex b/lib/safira_web/views/roulette_view.ex index c8055004..94f6d2eb 100644 --- a/lib/safira_web/views/roulette_view.ex +++ b/lib/safira_web/views/roulette_view.ex @@ -30,6 +30,10 @@ defmodule SafiraWeb.RouletteView do resp end + def render("price.json", %{price: price}) do + %{price: price} + end + def render("latest_prizes.json", %{latest_prizes: latest_prizes}) do %{data: render_many(latest_prizes, SafiraWeb.RouletteView, "latest_prize_show.json")} end From 1fc0e6f311f1620960b92bed2ab79d51fedbf339 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Lobo?= Date: Sat, 4 Nov 2023 21:38:44 +0000 Subject: [PATCH 2/2] fix: fetch wheel price from .env at compile time --- lib/safira_web/controllers/roulette_controller.ex | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/safira_web/controllers/roulette_controller.ex b/lib/safira_web/controllers/roulette_controller.ex index 11feb635..8c12d4ae 100644 --- a/lib/safira_web/controllers/roulette_controller.ex +++ b/lib/safira_web/controllers/roulette_controller.ex @@ -6,6 +6,8 @@ defmodule SafiraWeb.RouletteController do action_fallback SafiraWeb.FallbackController + @price Application.compile_env!(:safira, :roulette_cost) + def spin(conn, _params) do attendee = Accounts.get_user(conn) |> Map.fetch!(:attendee) @@ -32,7 +34,6 @@ defmodule SafiraWeb.RouletteController do end def price(conn, _params) do - price = Application.fetch_env!(:safira, :roulette_cost) - render(conn, "price.json", price: price) + render(conn, "price.json", price: @price) end end