Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: counts for day field in badge table #379

Merged
merged 2 commits into from
Feb 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions lib/mix/tasks/gen.badges.ex
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ defmodule Mix.Tasks.Gen.Badges do
end_badge,
image_path,
type,
tokens
tokens,
counts_for_day
] ->
{:ok, begin_datetime, _} = DateTime.from_iso8601(begin_time)
{:ok, end_datetime, _} = DateTime.from_iso8601(end_time)
Expand All @@ -82,7 +83,8 @@ defmodule Mix.Tasks.Gen.Badges do
begin_badge: begin_badge_datetime,
end_badge: end_badge_datetime,
type: String.to_integer(type),
tokens: String.to_integer(tokens)
tokens: String.to_integer(tokens),
counts_for_day: String.to_integer(counts_for_day) != 0
},
%{
avatar: get_avatar(image_path)
Expand Down
14 changes: 10 additions & 4 deletions lib/safira/contest/badge.ex
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ defmodule Safira.Contest.Badge do
field(:type, :integer)
field(:tokens, :integer)

field(:counts_for_day, :boolean, default: true)

has_many(:referrals, Referral)
many_to_many(:attendees, Attendee, join_through: Redeem)

Expand All @@ -45,7 +47,8 @@ defmodule Safira.Contest.Badge do
:begin_badge,
:end_badge,
:type,
:tokens
:tokens,
:counts_for_day
])
|> cast_attachments(attrs, [:avatar])
|> validate_required([
Expand All @@ -56,7 +59,8 @@ defmodule Safira.Contest.Badge do
:begin_badge,
:end_badge,
:type,
:tokens
:tokens,
:counts_for_day
])
|> validate_length(:name, min: 1, max: 255)
|> validate_length(:description, min: 1, max: 1000)
Expand All @@ -74,7 +78,8 @@ defmodule Safira.Contest.Badge do
:name,
:description,
:type,
:tokens
:tokens,
:counts_for_day
])
|> cast_attachments(attrs, [:avatar])
|> validate_required([
Expand All @@ -85,7 +90,8 @@ defmodule Safira.Contest.Badge do
:name,
:description,
:type,
:tokens
:tokens,
:counts_for_day
])
|> validate_length(:name, min: 1, max: 255)
|> validate_length(:description, min: 1, max: 1000)
Expand Down
3 changes: 2 additions & 1 deletion lib/safira/contest/contest.ex
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,8 @@ defmodule Safira.Contest do
join: t in DailyToken,
on: a.id == t.attendee_id,
where:
not is_nil(a.user_id) and fragment("?::date", r.inserted_at) == ^date and b.type != ^0 and
not is_nil(a.user_id) and fragment("?::date", r.inserted_at) == ^date and
b.counts_for_day and
fragment("?::date", t.day) == ^date,
select: %{attendee: a, token_count: t.quantity},
preload: [badges: b, daily_tokens: t]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
defmodule Safira.Repo.Migrations.AddCountsForDayToBadges do
use Ecto.Migration

def change do
alter table(:badges) do
add :counts_for_day, :boolean, default: true
end
end
end
Loading