Skip to content

Commit

Permalink
feat: add email to attendee view
Browse files Browse the repository at this point in the history
  • Loading branch information
joaodiaslobo committed Feb 5, 2024
1 parent 39291fa commit 3558726
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 6 deletions.
3 changes: 2 additions & 1 deletion lib/safira/accounts/accounts.ex
Original file line number Diff line number Diff line change
Expand Up @@ -257,9 +257,10 @@ defmodule Safira.Accounts do
join: a in assoc(r, :attendee),
preload: [attendee: a]
)
|> Enum.map(fn x -> x.attendee end)
|> Enum.map(fn x -> x.attendee |> Repo.preload(:user) end)
else
Repo.all(Attendee)
|> Repo.preload(:user)
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/safira/contest/contest.ex
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ defmodule Safira.Contest do

def get_badge_preload!(id) do
Repo.get!(Badge, id)
|> Repo.preload(:attendees)
|> Repo.preload(attendees: [:user])
end

def get_badge_description(description) do
Expand Down
2 changes: 2 additions & 0 deletions lib/safira_web/views/attendee_view.ex
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ defmodule SafiraWeb.AttendeeView do
%{
id: attendee.id,
nickname: attendee.nickname,
email: attendee.user.email,
name: attendee.name,
course: attendee.course_id,
avatar: Avatar.url({attendee.avatar, attendee}, :original),
Expand All @@ -86,6 +87,7 @@ defmodule SafiraWeb.AttendeeView do
%{
id: attendee.id,
nickname: attendee.nickname,
email: attendee.user.email,
name: attendee.name,
course: attendee.course_id,
avatar: Avatar.url({attendee.avatar, attendee}, :original),
Expand Down
9 changes: 6 additions & 3 deletions test/safira/accounts_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ defmodule Safira.AccountsTest do
attendee
|> forget(:user)

assert Accounts.list_company_attendees(company.id) == [attendee]
assert Accounts.list_company_attendees(company.id) == [attendee |> Repo.preload(:user)]
end

test "multiple attendees" do
Expand All @@ -513,7 +513,10 @@ defmodule Safira.AccountsTest do
attendee2
|> forget(:user)

assert Accounts.list_company_attendees(company.id) == [attendee1, attendee2]
assert Accounts.list_company_attendees(company.id) == [
attendee1 |> Repo.preload(:user),
attendee2 |> Repo.preload(:user)
]
end

test "attendee redeemed another Bronze company's badge" do
Expand All @@ -536,7 +539,7 @@ defmodule Safira.AccountsTest do
attendee1
|> forget(:user)

assert Accounts.list_company_attendees(company.id) == [attendee1]
assert Accounts.list_company_attendees(company.id) == [attendee1 |> Repo.preload(:user)]
end
end

Expand Down
3 changes: 2 additions & 1 deletion test/safira_web/controllers/attendee_controller_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,8 @@ defmodule SafiraWeb.AttendeeControllerTest do
"id" => attendee.id,
"name" => attendee.name,
"nickname" => "john_doe123",
"token_balance" => 0
"token_balance" => 0,
"email" => attendee.user.email
}

assert json_response(conn, 200)["data"] == expected_attendee
Expand Down
4 changes: 4 additions & 0 deletions test/safira_web/controllers/company_controller_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ defmodule SafiraWeb.CompanyControllerTest do
%{
"id" => attendee.id,
"nickname" => attendee.nickname,
"email" => attendee.user.email,
"name" => attendee.name,
"avatar" => nil,
"cv" => nil,
Expand Down Expand Up @@ -143,6 +144,7 @@ defmodule SafiraWeb.CompanyControllerTest do
%{
"id" => attendee1.id,
"nickname" => attendee1.nickname,
"email" => attendee1.user.email,
"name" => attendee1.name,
"course" => nil,
"avatar" => nil,
Expand All @@ -153,6 +155,7 @@ defmodule SafiraWeb.CompanyControllerTest do
%{
"id" => attendee2.id,
"nickname" => attendee2.nickname,
"email" => attendee2.user.email,
"name" => attendee2.name,
"course" => nil,
"avatar" => nil,
Expand Down Expand Up @@ -194,6 +197,7 @@ defmodule SafiraWeb.CompanyControllerTest do
%{
"id" => attendee1.id,
"nickname" => attendee1.nickname,
"email" => attendee1.user.email,
"name" => attendee1.name,
"course" => nil,
"avatar" => nil,
Expand Down

0 comments on commit 3558726

Please sign in to comment.