Skip to content

Commit

Permalink
fix: change application fetch envs to application compile envs
Browse files Browse the repository at this point in the history
  • Loading branch information
MarioRodrigues10 committed Nov 4, 2023
1 parent 1547be7 commit ca21975
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
4 changes: 3 additions & 1 deletion lib/safira/interaction/interaction.ex
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ defmodule Safira.Interaction do

alias Safira.Repo

@token_bonus Application.compile_env!(:safira, :token_bonus)

@doc """
Returns the list of bonuses.
Expand Down Expand Up @@ -134,7 +136,7 @@ defmodule Safira.Interaction do
|> Multi.update(
:update_attendee,
Attendee.update_token_balance_changeset(attendee, %{
token_balance: attendee.token_balance + Application.fetch_env!(:safira, :token_bonus)
token_balance: attendee.token_balance + @token_bonus
})
)
|> Multi.insert_or_update(:daily_token, fn %{update_attendee: attendee} ->
Expand Down
10 changes: 7 additions & 3 deletions lib/safira/roulette/roulette.ex
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ defmodule Safira.Roulette do
alias Safira.Roulette.Prize
alias Safira.Store

Check warning on line 19 in lib/safira/roulette/roulette.ex

View workflow job for this annotation

GitHub Actions / OTP 25.x / Elixir 1.14.x

unused alias Store

@roulette_cost Application.compile_env!(:safira, :roulette_cost)
@roulette_tokens_min Application.compile_env!(:safira, :roulette_tokens_min)
@roulette_tokens_max Application.compile_env!(:safira, :roulette_tokens_max)

@doc """
Returns the list of prizes.
Expand Down Expand Up @@ -247,7 +251,7 @@ defmodule Safira.Roulette do
|> Multi.update(
:attendee,
Attendee.update_token_balance_changeset(attendee, %{
token_balance: attendee.token_balance - Application.fetch_env!(:safira, :roulette_cost)
token_balance: attendee.token_balance - @roulette_cost
})
)
# prize after spinning
Expand Down Expand Up @@ -330,8 +334,8 @@ defmodule Safira.Roulette do
end

defp calculate_tokens(attendee) do
min = Application.fetch_env!(:safira, :roulette_tokens_min)
max = Application.fetch_env!(:safira, :roulette_tokens_max)
min = @roulette_tokens_min
max = @roulette_tokens_max
tokens = Enum.random(min..max)

Multi.new()
Expand Down
4 changes: 3 additions & 1 deletion lib/safira_web/views/bonus_view.ex
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
defmodule SafiraWeb.BonusView do
use SafiraWeb, :view

@token_bonus Application.compile_env!(:safira, :token_bonus)

def render("bonus.json", changes) do
attendee = Map.get(changes, :update_attendee)
bonus = Map.get(changes, :upsert_bonus)

%{
name: attendee.name,
attendee_id: attendee.id,
token_bonus: Application.fetch_env!(:safira, :token_bonus),
token_bonus: @token_bonus,
bonus_count: bonus.count,
company_id: bonus.company_id
}
Expand Down

0 comments on commit ca21975

Please sign in to comment.