Skip to content

Commit

Permalink
fix: change fetch envs to compile envs (#351)
Browse files Browse the repository at this point in the history
  • Loading branch information
MarioRodrigues10 authored Nov 4, 2023
1 parent 1547be7 commit b216957
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 9 deletions.
3 changes: 2 additions & 1 deletion config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ config :safira,
spotlight_duration: String.to_integer(System.get_env("SPOTLIGHT_DURATION") || "30"),
discord_bot_url: System.get_env("DISCORD_BOT_URL"),
discord_bot_api_key: System.get_env("DISCORD_BOT_API_KEY"),
discord_invite_url: System.get_env("DISCORD_INVITE_URL")
discord_invite_url: System.get_env("DISCORD_INVITE_URL"),
max_cv_file_size: String.to_integer(System.get_env("MAX_CV_SIZE") || "8000000")

# Configures the endpoint
config :safira, SafiraWeb.Endpoint,
Expand Down
4 changes: 2 additions & 2 deletions lib/safira/email.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ defmodule Safira.Email do
"""
# use Bamboo.Phoenix, view: Safira.FeedbackView
import Bamboo.Email

@from_email Application.compile_env!(:safira, :from_email)
def send_reset_email(to_email, token) do
new_email()
|> to(to_email)
|> from(System.get_env("FROM_EMAIL"))
|> from(@from_email)
|> subject("[SEI '23] Reset password instructions")
|> html_body(build_reset_password_email_text(token))
|> Safira.Mailer.deliver_now()
Expand Down
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

@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
2 changes: 1 addition & 1 deletion lib/safira/web/uploaders/cv.ex
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ defmodule Safira.CV do

@versions [:original]
@acl :public_read
@max_file_size String.to_integer(System.get_env("MAX_CV_FILE_SIZE") || "8000000")
@max_file_size Application.compile_env!(:safira, :max_cv_file_size)

def validate({file, _}) do
size = file_size(file)
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 b216957

Please sign in to comment.