From 232cf5b05aacd0a12e787bb4565f69c3acdab011 Mon Sep 17 00:00:00 2001 From: Rui Oliveira Date: Thu, 7 Sep 2023 11:54:02 +0100 Subject: [PATCH 01/19] build: migrate attendee, prize and redeemables views --- .../controllers/attendee_controller.ex | 2 +- lib/safira_web/controllers/attendee_json.ex | 94 +++++++++++++++++++ .../controllers/badge_controller.ex | 2 +- .../badge_json.ex} | 21 ++--- .../controllers/fallback_controller.ex | 2 +- .../controllers/prize_controller.ex | 2 +- lib/safira_web/controllers/prize_json.ex | 39 ++++++++ .../controllers/redeemable_controller.ex | 2 +- lib/safira_web/controllers/redeemable_json.ex | 61 ++++++++++++ lib/safira_web/views/redeemable_view.ex | 63 ------------- 10 files changed, 208 insertions(+), 80 deletions(-) create mode 100644 lib/safira_web/controllers/attendee_json.ex rename lib/safira_web/{views/badge_view.ex => controllers/badge_json.ex} (52%) create mode 100644 lib/safira_web/controllers/prize_json.ex create mode 100644 lib/safira_web/controllers/redeemable_json.ex delete mode 100644 lib/safira_web/views/redeemable_view.ex diff --git a/lib/safira_web/controllers/attendee_controller.ex b/lib/safira_web/controllers/attendee_controller.ex index dc372b2a..4f33f421 100644 --- a/lib/safira_web/controllers/attendee_controller.ex +++ b/lib/safira_web/controllers/attendee_controller.ex @@ -1,5 +1,5 @@ defmodule SafiraWeb.AttendeeController do - use SafiraWeb, controller: "1.6" + use SafiraWeb, :controller alias Safira.Accounts alias Safira.Accounts.Attendee diff --git a/lib/safira_web/controllers/attendee_json.ex b/lib/safira_web/controllers/attendee_json.ex new file mode 100644 index 00000000..697745ab --- /dev/null +++ b/lib/safira_web/controllers/attendee_json.ex @@ -0,0 +1,94 @@ +defmodule SafiraWeb.AttendeeJSON do + @moduledoc false + + alias Safira.Avatar + + alias Safira.CV + + alias SafiraWeb.BadgeJSON + alias SafiraWeb.PrizeJSON + alias SafiraWeb.RedeemableJSON + + def index(%{attendees: attendees}) do + %{data: for(at <- attendees, do: multiple_attendees(%{attendee: at}))} + end + + def show(%{attendee: at}) do + %{data: attendee(%{attendee: at})} + end + + def show_simple(%{attendee: at}) do + %{data: attendee_simple(%{attendee: at})} + end + + def manager_show(%{attendee: at}) do + %{data: manager_attendee(%{attendee: at})} + end + + def attendee(%{attendee: at}) do + %{ + id: at.id, + nickname: at.nickname, + name: at.name, + avatar: Avatar.url({at.avatar, at}, :original), + cv: CV.url({at.cv, at}, :original), + badges: for(b <- at.badges, do: BadgeJSON.badge(%{badge: b})), + badge_count: at.badge_count, + token_balance: at.token_balance, + prizes: for(p <- at.prizes, do: PrizeJSON.prize_attendee(%{prize: p})), + entries: at.entries, + redeemables: for(r <- at.redeemables, do: RedeemableJSON.my_readeemables(%{redeemable: r})) + } + end + + def multiple_attendees(%{attendee: at}) do + %{ + id: at.id, + nickname: at.nickname, + name: at.name, + avatar: Avatar.url({at.avatar, at}, :original), + cv: CV.url({at.cv, at}, :original), + badges: for(b <- at.badges, do: BadgeJSON.badge(%{badge: b})), + badge_count: at.badge_count, + token_balance: at.token_balance, + entries: at.entries + } + end + + def manager_attendee(%{attendee: at}) do + %{ + id: at.id, + nickname: at.nickname, + name: at.name, + email: at.user.email, + avatar: Avatar.url({at.avatar, at}, :original), + cv: CV.url({at.cv, at}, :original), + badges: for(b <- at.badges, do: BadgeJSON.badge(%{badge: b})), + badge_count: at.badge_count + } + end + + def attendee_simple( %{attendee: at}) do + %{ + id: at.id, + nickname: at.nickname, + name: at.name, + avatar: Avatar.url({at.avatar, at}, :original), + cv: CV.url({at.cv, at}, :original), + token_balance: at.token_balance, + entries: at.entries + } + end + + def attendee_no_cv(%{attendee: at}) do + %{ + id: at.id, + nickname: at.nickname, + name: at.name, + avatar: Avatar.url({at.avatar, at}, :original), + cv: nil, + token_balance: at.token_balance, + entries: at.entries + } + end +end diff --git a/lib/safira_web/controllers/badge_controller.ex b/lib/safira_web/controllers/badge_controller.ex index 339ebcc8..ed4e78ac 100644 --- a/lib/safira_web/controllers/badge_controller.ex +++ b/lib/safira_web/controllers/badge_controller.ex @@ -1,5 +1,5 @@ defmodule SafiraWeb.BadgeController do - use SafiraWeb, controller: "1.6" + use SafiraWeb, :controller alias Safira.Accounts alias Safira.Contest diff --git a/lib/safira_web/views/badge_view.ex b/lib/safira_web/controllers/badge_json.ex similarity index 52% rename from lib/safira_web/views/badge_view.ex rename to lib/safira_web/controllers/badge_json.ex index d9de0c0c..b1a027d5 100644 --- a/lib/safira_web/views/badge_view.ex +++ b/lib/safira_web/controllers/badge_json.ex @@ -1,20 +1,17 @@ -defmodule SafiraWeb.BadgeView do - use SafiraWeb, :view +defmodule SafiraWeb.BadgeJSON do + alias SafiraWeb.AttendeeJSON alias Safira.Avatar - alias SafiraWeb.AttendeeView - alias SafiraWeb.BadgeView - - def render("index.json", %{badges: badges}) do - %{data: render_many(badges, BadgeView, "badge.json")} + def index(%{badges: badges}) do + %{data: for(b <- badges, do: badge(%{badge: b}))} end - def render("show.json", %{badge: badge}) do - %{data: render_one(badge, BadgeView, "badge_show.json")} + def show(%{badge: badge}) do + %{data: badge_show(%{badge: badge})} end - def render("badge.json", %{badge: badge}) do + def badge(%{badge: badge}) do %{ id: badge.id, name: badge.name, @@ -27,7 +24,7 @@ defmodule SafiraWeb.BadgeView do } end - def render("badge_show.json", %{badge: badge}) do + def badge_show(%{badge: badge}) do %{ id: badge.id, name: badge.name, @@ -37,7 +34,7 @@ defmodule SafiraWeb.BadgeView do end: badge.end, type: badge.type, tokens: badge.tokens, - attendees: render_many(badge.attendees, AttendeeView, "attendee_simple.json") + attendees: for(at <- badge.attendees, do: AttendeeJSON.attendee_simple(%{attendee: at})) } end end diff --git a/lib/safira_web/controllers/fallback_controller.ex b/lib/safira_web/controllers/fallback_controller.ex index 53e0287e..a773ff2d 100644 --- a/lib/safira_web/controllers/fallback_controller.ex +++ b/lib/safira_web/controllers/fallback_controller.ex @@ -4,7 +4,7 @@ defmodule SafiraWeb.FallbackController do See `Phoenix.Controller.action_fallback/1` for more details. """ - use SafiraWeb, controller: "1.6" + use SafiraWeb, :controller def call(conn, {:error, :register_error}) do conn diff --git a/lib/safira_web/controllers/prize_controller.ex b/lib/safira_web/controllers/prize_controller.ex index 924bd5e1..ca479a24 100644 --- a/lib/safira_web/controllers/prize_controller.ex +++ b/lib/safira_web/controllers/prize_controller.ex @@ -1,5 +1,5 @@ defmodule SafiraWeb.PrizeController do - use SafiraWeb, controller: "1.6" + use SafiraWeb, :controller alias Safira.Roulette diff --git a/lib/safira_web/controllers/prize_json.ex b/lib/safira_web/controllers/prize_json.ex new file mode 100644 index 00000000..02ba4049 --- /dev/null +++ b/lib/safira_web/controllers/prize_json.ex @@ -0,0 +1,39 @@ +defmodule SafiraWeb.PrizeJSON do + alias Safira.Avatar + + def index(%{prizes: prizes}) do + %{data: for(p <- prizes, do: prize_show(%{prize: p}))} + end + + def show(%{prize: prize}) do + %{data: prize_show(%{prize: prize})} + end + + def prize(%{prize: prize}) do + %{ + id: prize.id, + name: prize.name, + avatar: Avatar.url({prize.avatar, prize}, :original) + } + end + + def prize_attendee(%{prize: prize}) do + %{ + id: prize.id, + name: prize.name, + avatar: Avatar.url({prize.avatar, prize}, :original), + not_redeemed: prize.not_redeemed, + is_redeemable: prize.is_redeemable + } + end + + def prize_show(%{prize: prize}) do + %{ + id: prize.id, + name: prize.name, + avatar: Avatar.url({prize.avatar, prize}, :original), + max_amount_per_attendee: prize.max_amount_per_attendee, + stock: prize.stock + } + end +end diff --git a/lib/safira_web/controllers/redeemable_controller.ex b/lib/safira_web/controllers/redeemable_controller.ex index c3eb1590..d0230d1e 100644 --- a/lib/safira_web/controllers/redeemable_controller.ex +++ b/lib/safira_web/controllers/redeemable_controller.ex @@ -1,5 +1,5 @@ defmodule SafiraWeb.RedeemableController do - use SafiraWeb, controller: "1.6" + use SafiraWeb, :controller alias Safira.Accounts diff --git a/lib/safira_web/controllers/redeemable_json.ex b/lib/safira_web/controllers/redeemable_json.ex new file mode 100644 index 00000000..585af637 --- /dev/null +++ b/lib/safira_web/controllers/redeemable_json.ex @@ -0,0 +1,61 @@ +defmodule SafiraWeb.RedeemableJSON do + + alias Safira.Avatar + + def index(%{redeemables: redeemables}) do + %{data: for(r <- redeemables, do: redeemables(%{redeemable: r}))} + end + + def index_my_redeemables(%{redeemables: redeemables}) do + %{data: for(r <- redeemables, do: my_redeemables(%{redeemable: r}))} + end + + def index_non_attendee(%{redeemables: redeemables}) do + %{data: for(r <- redeemables, do: non_attendee_redeemables(%{redeemable: r}))} + end + + def show(%{redeemable: redeemable}) do + %{data: redeemables(%{redeemable: redeemable})} + end + + def show_non_attendee(%{redeemable: redeemable}) do + %{data: non_attendee_redeemables(%{redeemable: redeemable})} + end + + def redeemables(%{redeemable: redeemable}) do + %{ + id: redeemable.id, + name: redeemable.name, + description: redeemable.description, + image: Avatar.url({redeemable.img, redeemable}, :original), + price: redeemable.price, + stock: redeemable.stock, + max_per_user: redeemable.max_per_user, + can_buy: redeemable.can_buy + } + end + + def my_redeemables(%{redeemable: redeemable}) do + %{ + id: redeemable.id, + name: redeemable.name, + image: Avatar.url({redeemable.img, redeemable}, :original), + price: redeemable.price, + quantity: redeemable.quantity, + not_redeemed: redeemable.not_redeemed + } + end + + def non_attendee_redeemables(%{redeemable: redeemable}) do + %{ + id: redeemable.id, + name: redeemable.name, + description: redeemable.description, + image: Avatar.url({redeemable.img, redeemable}, :original), + price: redeemable.price, + stock: redeemable.stock, + max_per_user: redeemable.max_per_user, + can_buy: 0 + } + end +end diff --git a/lib/safira_web/views/redeemable_view.ex b/lib/safira_web/views/redeemable_view.ex deleted file mode 100644 index 545e28f4..00000000 --- a/lib/safira_web/views/redeemable_view.ex +++ /dev/null @@ -1,63 +0,0 @@ -defmodule SafiraWeb.RedeemableView do - use SafiraWeb, :view - - alias Safira.Avatar - alias SafiraWeb.RedeemableView - - def render("index.json", %{redeemables: redeemables}) do - %{data: render_many(redeemables, RedeemableView, "redeemables.json")} - end - - def render("index_my_redeemables.json", %{redeemables: redeemables}) do - %{data: render_many(redeemables, RedeemableView, "my_redeemables.json")} - end - - def render("index_non_attendee.json", %{redeemables: redeemables}) do - %{data: render_many(redeemables, RedeemableView, "non_attendee_redeemables.json")} - end - - def render("show.json", %{redeemable: redeemable}) do - %{data: render_one(redeemable, RedeemableView, "redeemables.json")} - end - - def render("show_non_attendee.json", %{redeemable: redeemable}) do - %{data: render_one(redeemable, RedeemableView, "non_attendee_redeemables.json")} - end - - def render("redeemables.json", %{redeemable: redeemable}) do - %{ - id: redeemable.id, - name: redeemable.name, - description: redeemable.description, - image: Avatar.url({redeemable.img, redeemable}, :original), - price: redeemable.price, - stock: redeemable.stock, - max_per_user: redeemable.max_per_user, - can_buy: redeemable.can_buy - } - end - - def render("my_redeemables.json", %{redeemable: redeemable}) do - %{ - id: redeemable.id, - name: redeemable.name, - image: Avatar.url({redeemable.img, redeemable}, :original), - price: redeemable.price, - quantity: redeemable.quantity, - not_redeemed: redeemable.not_redeemed - } - end - - def render("non_attendee_redeemables.json", %{redeemable: redeemable}) do - %{ - id: redeemable.id, - name: redeemable.name, - description: redeemable.description, - image: Avatar.url({redeemable.img, redeemable}, :original), - price: redeemable.price, - stock: redeemable.stock, - max_per_user: redeemable.max_per_user, - can_buy: 0 - } - end -end From 6c083c1b97a3c19749e1e3e56722e2fab9005671 Mon Sep 17 00:00:00 2001 From: Rui Oliveira Date: Thu, 7 Sep 2023 11:56:32 +0100 Subject: [PATCH 02/19] build: migrate bonus view --- lib/safira_web/controllers/bonus_controller.ex | 2 +- .../{views/bonus_view.ex => controllers/bonus_json.ex} | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) rename lib/safira_web/{views/bonus_view.ex => controllers/bonus_json.ex} (78%) diff --git a/lib/safira_web/controllers/bonus_controller.ex b/lib/safira_web/controllers/bonus_controller.ex index 08318bdf..d1cf3791 100644 --- a/lib/safira_web/controllers/bonus_controller.ex +++ b/lib/safira_web/controllers/bonus_controller.ex @@ -1,5 +1,5 @@ defmodule SafiraWeb.BonusController do - use SafiraWeb, controller: "1.6" + use SafiraWeb, :controller alias Safira.Accounts alias Safira.Interaction diff --git a/lib/safira_web/views/bonus_view.ex b/lib/safira_web/controllers/bonus_json.ex similarity index 78% rename from lib/safira_web/views/bonus_view.ex rename to lib/safira_web/controllers/bonus_json.ex index d1213ab1..693478e1 100644 --- a/lib/safira_web/views/bonus_view.ex +++ b/lib/safira_web/controllers/bonus_json.ex @@ -1,9 +1,8 @@ -defmodule SafiraWeb.BonusView do - use SafiraWeb, :view +defmodule SafiraWeb.BonusJSON do @token_bonus Application.compile_env!(:safira, :token_bonus) - def render("bonus.json", changes) do + def bonus(changes) do attendee = Map.get(changes, :update_attendee) bonus = Map.get(changes, :upsert_bonus) From 40be1715769371dbd1ba46cca8594806e39d85f4 Mon Sep 17 00:00:00 2001 From: Rui Oliveira Date: Thu, 7 Sep 2023 11:57:31 +0100 Subject: [PATCH 03/19] build: migrate buy view --- lib/safira_web/controllers/buy_controller.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/safira_web/controllers/buy_controller.ex b/lib/safira_web/controllers/buy_controller.ex index 01dcbd4a..d3bc1d7e 100644 --- a/lib/safira_web/controllers/buy_controller.ex +++ b/lib/safira_web/controllers/buy_controller.ex @@ -1,5 +1,5 @@ defmodule SafiraWeb.BuyController do - use SafiraWeb, controller: "1.6" + use SafiraWeb, :controller alias Safira.Accounts From f6d4696977dd0c0483b0254d82bdf5313e0548d8 Mon Sep 17 00:00:00 2001 From: Rui Oliveira Date: Thu, 7 Sep 2023 12:03:46 +0100 Subject: [PATCH 04/19] build: migrate company view --- .../controllers/company_controller.ex | 2 +- lib/safira_web/controllers/company_json.ex | 32 ++++++++++++++++++ lib/safira_web/views/company_view.ex | 33 ------------------- 3 files changed, 33 insertions(+), 34 deletions(-) create mode 100644 lib/safira_web/controllers/company_json.ex delete mode 100644 lib/safira_web/views/company_view.ex diff --git a/lib/safira_web/controllers/company_controller.ex b/lib/safira_web/controllers/company_controller.ex index 19faa33c..66be0cc1 100644 --- a/lib/safira_web/controllers/company_controller.ex +++ b/lib/safira_web/controllers/company_controller.ex @@ -1,5 +1,5 @@ defmodule SafiraWeb.CompanyController do - use SafiraWeb, controller: "1.6" + use SafiraWeb, :controller alias Safira.Accounts diff --git a/lib/safira_web/controllers/company_json.ex b/lib/safira_web/controllers/company_json.ex new file mode 100644 index 00000000..22a0973d --- /dev/null +++ b/lib/safira_web/controllers/company_json.ex @@ -0,0 +1,32 @@ +defmodule SafiraWeb.CompanyJSON do + @moduledoc false + + alias SafiraWeb.AttendeeJSON + + def index(%{companies: companies}) do + %{data: for(c <- companies, do: company_show(%{company: c}))} + end + + def show(%{company: company}) do + %{data: company_show(%{company: company})} + end + + def company_show(%{company: company}) do + %{ + id: company.id, + name: company.name, + sponsorship: company.sponsorship, + channel_id: company.channel_id, + badge_id: company.badge_id, + has_cv_access: company.has_cv_access + } + end + + def index_attendees(%{attendees: attendees, show_cv: show_cv}) do + if show_cv do + %{data: for(at <- attendees, do: AttendeeJSON.attendee_simple(%{attendee: at}))} + else + %{data: for(at <- attendees, do: AttendeeJSON.attendee_no_cv(%{attendee: at}))} + end + end +end diff --git a/lib/safira_web/views/company_view.ex b/lib/safira_web/views/company_view.ex deleted file mode 100644 index cd1a9152..00000000 --- a/lib/safira_web/views/company_view.ex +++ /dev/null @@ -1,33 +0,0 @@ -defmodule SafiraWeb.CompanyView do - use SafiraWeb, :view - alias SafiraWeb.CompanyView - - alias SafiraWeb.AttendeeView - - def render("index.json", %{companies: companies}) do - %{data: render_many(companies, CompanyView, "company.json")} - end - - def render("show.json", %{company: company}) do - %{data: render_one(company, CompanyView, "company.json")} - end - - def render("company.json", %{company: company}) do - %{ - id: company.id, - name: company.name, - sponsorship: company.sponsorship, - channel_id: company.channel_id, - badge_id: company.badge_id, - has_cv_access: company.has_cv_access - } - end - - def render("index_attendees.json", %{attendees: attendees, show_cv: show_cv}) do - if show_cv do - %{data: render_many(attendees, AttendeeView, "attendee_simple.json")} - else - %{data: render_many(attendees, AttendeeView, "attendee_no_cv.json")} - end - end -end From 9c9ee8baa7e3fa17ea0f14d72506ba963dc0032c Mon Sep 17 00:00:00 2001 From: Rui Oliveira Date: Thu, 7 Sep 2023 12:04:22 +0100 Subject: [PATCH 05/19] build: migrate cv view --- lib/safira_web/controllers/cv_controller.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/safira_web/controllers/cv_controller.ex b/lib/safira_web/controllers/cv_controller.ex index 8215702b..d69dc016 100644 --- a/lib/safira_web/controllers/cv_controller.ex +++ b/lib/safira_web/controllers/cv_controller.ex @@ -1,5 +1,5 @@ defmodule SafiraWeb.CVController do - use SafiraWeb, controller: "1.6" + use SafiraWeb, :controller alias Safira.Accounts From 0a63b5063bf30cd44768d675ab685a290c1d76a9 Mon Sep 17 00:00:00 2001 From: Rui Oliveira Date: Thu, 7 Sep 2023 12:06:59 +0100 Subject: [PATCH 06/19] build: migrate deliver_prize view --- .../controllers/deliver_prize_controller.ex | 2 +- .../controllers/deliver_prize_json.ex | 18 +++++++++++++++++ lib/safira_web/views/deliver_prize_view.ex | 20 ------------------- 3 files changed, 19 insertions(+), 21 deletions(-) create mode 100644 lib/safira_web/controllers/deliver_prize_json.ex delete mode 100644 lib/safira_web/views/deliver_prize_view.ex diff --git a/lib/safira_web/controllers/deliver_prize_controller.ex b/lib/safira_web/controllers/deliver_prize_controller.ex index 814c8722..236bc62e 100644 --- a/lib/safira_web/controllers/deliver_prize_controller.ex +++ b/lib/safira_web/controllers/deliver_prize_controller.ex @@ -1,5 +1,5 @@ defmodule SafiraWeb.DeliverPrizeController do - use SafiraWeb, controller: "1.6" + use SafiraWeb, :controller alias Safira.Accounts diff --git a/lib/safira_web/controllers/deliver_prize_json.ex b/lib/safira_web/controllers/deliver_prize_json.ex new file mode 100644 index 00000000..92fee6e9 --- /dev/null +++ b/lib/safira_web/controllers/deliver_prize_json.ex @@ -0,0 +1,18 @@ +defmodule SafiraWeb.DeliverPrizeJSON do + @moduledoc false + + alias Safira.Avatar + + def index(%{delivers: delivers}) do + %{data: for(d <- delivers, do: delivers(%{deliver_prize: d}))} + end + + def delivers(%{deliver_prize: deliver}) do + %{ + id: deliver.id, + name: deliver.name, + image: Avatar.url({deliver.avatar, deliver}, :original), + not_redeemed: deliver.not_redeemed + } + end +end diff --git a/lib/safira_web/views/deliver_prize_view.ex b/lib/safira_web/views/deliver_prize_view.ex deleted file mode 100644 index 2d38f72e..00000000 --- a/lib/safira_web/views/deliver_prize_view.ex +++ /dev/null @@ -1,20 +0,0 @@ -defmodule SafiraWeb.DeliverPrizeView do - use SafiraWeb, :view - - alias Safira.Avatar - - alias SafiraWeb.DeliverPrizeView - - def render("index.json", %{delivers: delivers}) do - %{data: render_many(delivers, DeliverPrizeView, "delivers.json")} - end - - def render("delivers.json", %{deliver_prize: deliver}) do - %{ - id: deliver.id, - name: deliver.name, - image: Avatar.url({deliver.avatar, deliver}, :original), - not_redeemed: deliver.not_redeemed - } - end -end From fd145d60b4cbf984788ecc8068f4652b7cf4a4b7 Mon Sep 17 00:00:00 2001 From: Rui Oliveira Date: Thu, 7 Sep 2023 12:11:13 +0100 Subject: [PATCH 07/19] build: migrate deliver_redeemable view --- .../deliver_redeemable_controller.ex | 2 +- .../controllers/deliver_redeemable_json.ex | 17 ++++++++++++++++ .../views/deliver_redeemable_view.ex | 20 ------------------- 3 files changed, 18 insertions(+), 21 deletions(-) create mode 100644 lib/safira_web/controllers/deliver_redeemable_json.ex delete mode 100644 lib/safira_web/views/deliver_redeemable_view.ex diff --git a/lib/safira_web/controllers/deliver_redeemable_controller.ex b/lib/safira_web/controllers/deliver_redeemable_controller.ex index dda3185c..f4ea8e26 100644 --- a/lib/safira_web/controllers/deliver_redeemable_controller.ex +++ b/lib/safira_web/controllers/deliver_redeemable_controller.ex @@ -1,5 +1,5 @@ defmodule SafiraWeb.DeliverRedeemableController do - use SafiraWeb, controller: "1.6" + use SafiraWeb, :controller alias Safira.Accounts diff --git a/lib/safira_web/controllers/deliver_redeemable_json.ex b/lib/safira_web/controllers/deliver_redeemable_json.ex new file mode 100644 index 00000000..d0accb88 --- /dev/null +++ b/lib/safira_web/controllers/deliver_redeemable_json.ex @@ -0,0 +1,17 @@ +defmodule SafiraWeb.DeliverRedeemableJSON do + @moduledoc false + alias Safira.Avatar + + def index(%{delivers: delivers}) do + %{data: for(d <- delivers, do: delivers_show(%{deliver_redeemable: d}))} + end + + def delivers_show(%{deliver_redeemable: deliver}) do + %{ + id: deliver.id, + name: deliver.name, + image: Avatar.url({deliver.img, deliver}, :original), + not_redeemed: deliver.not_redeemed + } + end +end diff --git a/lib/safira_web/views/deliver_redeemable_view.ex b/lib/safira_web/views/deliver_redeemable_view.ex deleted file mode 100644 index 8f13b980..00000000 --- a/lib/safira_web/views/deliver_redeemable_view.ex +++ /dev/null @@ -1,20 +0,0 @@ -defmodule SafiraWeb.DeliverRedeemableView do - use SafiraWeb, :view - - alias Safira.Avatar - - alias SafiraWeb.DeliverRedeemableView - - def render("index.json", %{delivers: delivers}) do - %{data: render_many(delivers, DeliverRedeemableView, "delivers.json")} - end - - def render("delivers.json", %{deliver_redeemable: deliver}) do - %{ - id: deliver.id, - name: deliver.name, - image: Avatar.url({deliver.img, deliver}, :original), - not_redeemed: deliver.not_redeemed - } - end -end From a7c353318e9ab2a7f71d3908809ba4ddd5323df1 Mon Sep 17 00:00:00 2001 From: Rui Oliveira Date: Thu, 7 Sep 2023 15:04:57 +0100 Subject: [PATCH 08/19] build: migrate page_controller --- lib/safira_web/controllers/page_controller.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/safira_web/controllers/page_controller.ex b/lib/safira_web/controllers/page_controller.ex index 1328c06f..6ebdf41e 100644 --- a/lib/safira_web/controllers/page_controller.ex +++ b/lib/safira_web/controllers/page_controller.ex @@ -1,5 +1,5 @@ defmodule SafiraWeb.PageController do - use SafiraWeb, controller: "1.6" + use SafiraWeb, :controller def index(conn, _params) do conn From 39aeac693ac4a36892759d28c835f162b82ca1ea Mon Sep 17 00:00:00 2001 From: Rui Oliveira Date: Thu, 7 Sep 2023 15:09:42 +0100 Subject: [PATCH 09/19] build: migrate password view to 1.7 --- lib/safira_web/controllers/password_controller.ex | 2 +- .../password_view.ex => controllers/password_json.ex} | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) rename lib/safira_web/{views/password_view.ex => controllers/password_json.ex} (66%) diff --git a/lib/safira_web/controllers/password_controller.ex b/lib/safira_web/controllers/password_controller.ex index 86890254..a88eca5f 100644 --- a/lib/safira_web/controllers/password_controller.ex +++ b/lib/safira_web/controllers/password_controller.ex @@ -1,5 +1,5 @@ defmodule SafiraWeb.PasswordController do - use SafiraWeb, controller: "1.6" + use SafiraWeb, :controller alias Safira.Accounts alias Safira.Accounts.User diff --git a/lib/safira_web/views/password_view.ex b/lib/safira_web/controllers/password_json.ex similarity index 66% rename from lib/safira_web/views/password_view.ex rename to lib/safira_web/controllers/password_json.ex index bc69ebb8..c897ad0b 100644 --- a/lib/safira_web/views/password_view.ex +++ b/lib/safira_web/controllers/password_json.ex @@ -1,7 +1,7 @@ -defmodule SafiraWeb.PasswordView do - use SafiraWeb, :view +defmodule SafiraWeb.PasswordJSON do + @moduledoc false - def render("show.json", %{}) do + def show(%{}) do %{ data: %{ attributes: %{ @@ -12,11 +12,11 @@ defmodule SafiraWeb.PasswordView do } end - def render("ok.json", %{}) do + def ok(%{}) do %{data: %{attributes: %{info: "User password successfully updated."}}} end - def render("error.json", %{error: error}) do + def error(%{error: error}) do %{errors: [%{detail: error}]} end end From 00098f4c80180c1bb4625b01e78a196c2551d32a Mon Sep 17 00:00:00 2001 From: Rui Oliveira Date: Thu, 7 Sep 2023 15:11:10 +0100 Subject: [PATCH 10/19] build: migrate redeem controller to 1.7 --- lib/safira_web/controllers/redeem_controller.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/safira_web/controllers/redeem_controller.ex b/lib/safira_web/controllers/redeem_controller.ex index 9e4c6cca..f16ce62f 100644 --- a/lib/safira_web/controllers/redeem_controller.ex +++ b/lib/safira_web/controllers/redeem_controller.ex @@ -1,5 +1,5 @@ defmodule SafiraWeb.RedeemController do - use SafiraWeb, controller: "1.6" + use SafiraWeb, :controller alias Safira.Accounts From fe0f4bdba0706f37d0a115d18fedcd800d459af4 Mon Sep 17 00:00:00 2001 From: Rui Oliveira Date: Thu, 7 Sep 2023 15:12:58 +0100 Subject: [PATCH 11/19] build: migrate referral controller to 1.7 --- .../controllers/referral_controller.ex | 2 +- lib/safira_web/views/referral_view.ex | 16 ---------------- 2 files changed, 1 insertion(+), 17 deletions(-) delete mode 100644 lib/safira_web/views/referral_view.ex diff --git a/lib/safira_web/controllers/referral_controller.ex b/lib/safira_web/controllers/referral_controller.ex index 43b9db11..08a4afa5 100644 --- a/lib/safira_web/controllers/referral_controller.ex +++ b/lib/safira_web/controllers/referral_controller.ex @@ -1,5 +1,5 @@ defmodule SafiraWeb.ReferralController do - use SafiraWeb, controller: "1.6" + use SafiraWeb, :controller alias Safira.Accounts alias Safira.Contest diff --git a/lib/safira_web/views/referral_view.ex b/lib/safira_web/views/referral_view.ex deleted file mode 100644 index a886e366..00000000 --- a/lib/safira_web/views/referral_view.ex +++ /dev/null @@ -1,16 +0,0 @@ -defmodule SafiraWeb.ReferralView do - use SafiraWeb, :view - alias SafiraWeb.ReferralView - - def render("index.json", %{referrals: referrals}) do - %{data: render_many(referrals, ReferralView, "referral.json")} - end - - def render("show.json", %{referral: referral}) do - %{data: render_one(referral, ReferralView, "referral.json")} - end - - def render("referral.json", %{referral: referral}) do - %{id: referral.id, available: referral.available} - end -end From 92507547359179089e2590a2dc4f6369a5a53670 Mon Sep 17 00:00:00 2001 From: Rui Oliveira Date: Thu, 7 Sep 2023 15:19:19 +0100 Subject: [PATCH 12/19] build: migrate roulette view to 1.7 --- .../controllers/roulette_controller.ex | 2 +- .../roulette_json.ex} | 25 +++++++++---------- 2 files changed, 13 insertions(+), 14 deletions(-) rename lib/safira_web/{views/roulette_view.ex => controllers/roulette_json.ex} (52%) diff --git a/lib/safira_web/controllers/roulette_controller.ex b/lib/safira_web/controllers/roulette_controller.ex index 8c12d4ae..4393ecfd 100644 --- a/lib/safira_web/controllers/roulette_controller.ex +++ b/lib/safira_web/controllers/roulette_controller.ex @@ -1,5 +1,5 @@ defmodule SafiraWeb.RouletteController do - use SafiraWeb, controller: "1.6" + use SafiraWeb, :controller alias Safira.Accounts alias Safira.Roulette diff --git a/lib/safira_web/views/roulette_view.ex b/lib/safira_web/controllers/roulette_json.ex similarity index 52% rename from lib/safira_web/views/roulette_view.ex rename to lib/safira_web/controllers/roulette_json.ex index 94f6d2eb..290b6010 100644 --- a/lib/safira_web/views/roulette_view.ex +++ b/lib/safira_web/controllers/roulette_json.ex @@ -1,7 +1,10 @@ -defmodule SafiraWeb.RouletteView do - use SafiraWeb, :view +defmodule SafiraWeb.RouletteJSON do + @moduledoc false - def render("roulette.json", changes) do + alias SafiraWeb.BadgeJSON + alias SafiraWeb.PrizeJSON + + def roulette(changes) do prize = Map.get(changes, :prize) attendee = Map.get(changes, :attendee) attendee_token_balance = Map.get(changes, :attendee_token_balance) @@ -9,7 +12,7 @@ defmodule SafiraWeb.RouletteView do badge = Map.get(changes, :badge) resp = %{ - prize: render_one(prize, SafiraWeb.PrizeView, "prize.json") + prize: PrizeJSON.prize(%{prize: prize}) } resp = @@ -21,7 +24,7 @@ defmodule SafiraWeb.RouletteView do Map.put(resp, :entries, 1) not is_nil(badge) -> - Map.put(resp, :badge, render_one(badge, SafiraWeb.BadgeView, "badge.json")) + Map.put(resp, :badge, BadgeJSON.badge(badge)) true -> resp @@ -30,18 +33,14 @@ 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")} + def latest_prizes(%{latest_prizes: latest_prizes}) do + %{data: for(p <- latest_prizes, do: latest_prize_show(%{roulette: p}))} end - def render("latest_prize_show.json", %{roulette: latest_prize}) do + def latest_prize_show(%{roulette: latest_prize}) do %{ attendee_name: elem(latest_prize, 0), - prize: render_one(elem(latest_prize, 1), SafiraWeb.PrizeView, "prize_show.json"), + prize: PrizeJSON.prize_show(%{prize: elem(latest_prize, 1)}), date: elem(latest_prize, 2) } end From 2cdbad47da906dfa8deae424bd20912e06996a49 Mon Sep 17 00:00:00 2001 From: Rui Oliveira Date: Thu, 7 Sep 2023 15:19:49 +0100 Subject: [PATCH 13/19] build: migrate spotlight controller to 1.7 --- lib/safira_web/controllers/spotlight_controller.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/safira_web/controllers/spotlight_controller.ex b/lib/safira_web/controllers/spotlight_controller.ex index 61449d53..155ab5c1 100644 --- a/lib/safira_web/controllers/spotlight_controller.ex +++ b/lib/safira_web/controllers/spotlight_controller.ex @@ -1,5 +1,5 @@ defmodule SafiraWeb.SpotlightController do - use SafiraWeb, controller: "1.6" + use SafiraWeb, :controller alias Safira.Accounts alias Safira.Interaction From 09306a0b3a7c53b118677038ba33ffa63882505b Mon Sep 17 00:00:00 2001 From: Rui Oliveira Date: Fri, 8 Sep 2023 16:09:35 +0100 Subject: [PATCH 14/19] build: migrate error views --- config/config.exs | 2 +- lib/safira_web/controllers/attendee_json.ex | 6 +- lib/safira_web/controllers/badge_json.ex | 1 - lib/safira_web/controllers/bonus_json.ex | 1 - lib/safira_web/controllers/buy_controller.ex | 4 + .../error_json.ex} | 41 +++++--- .../controllers/fallback_controller.ex | 11 ++- lib/safira_web/controllers/redeemable_json.ex | 1 - lib/safira_web/views/admin/attendee_view.ex | 6 -- lib/safira_web/views/admin/badge_view.ex | 6 -- lib/safira_web/views/admin/company_view.ex | 6 -- lib/safira_web/views/admin/redeem_view.ex | 6 -- lib/safira_web/views/admin/referral_view.ex | 6 -- lib/safira_web/views/admin/staff_view.ex | 6 -- lib/safira_web/views/attendee_view.ex | 97 ------------------- lib/safira_web/views/changeset_view.ex | 19 ---- lib/safira_web/views/error_view.ex | 25 ----- lib/safira_web/views/layout_view.ex | 3 - lib/safira_web/views/pow/registration_view.ex | 3 - lib/safira_web/views/pow/session_view.ex | 3 - lib/safira_web/views/prize_view.ex | 42 -------- test/safira_web/views/error_view_test.exs | 16 --- 22 files changed, 45 insertions(+), 266 deletions(-) rename lib/safira_web/{views/error_helpers.ex => controllers/error_json.ex} (61%) delete mode 100644 lib/safira_web/views/admin/attendee_view.ex delete mode 100644 lib/safira_web/views/admin/badge_view.ex delete mode 100644 lib/safira_web/views/admin/company_view.ex delete mode 100644 lib/safira_web/views/admin/redeem_view.ex delete mode 100644 lib/safira_web/views/admin/referral_view.ex delete mode 100644 lib/safira_web/views/admin/staff_view.ex delete mode 100644 lib/safira_web/views/attendee_view.ex delete mode 100644 lib/safira_web/views/changeset_view.ex delete mode 100644 lib/safira_web/views/error_view.ex delete mode 100644 lib/safira_web/views/layout_view.ex delete mode 100644 lib/safira_web/views/pow/registration_view.ex delete mode 100644 lib/safira_web/views/pow/session_view.ex delete mode 100644 lib/safira_web/views/prize_view.ex delete mode 100644 test/safira_web/views/error_view_test.exs diff --git a/config/config.exs b/config/config.exs index 9bc80908..411003f6 100644 --- a/config/config.exs +++ b/config/config.exs @@ -28,7 +28,7 @@ config :safira, config :safira, SafiraWeb.Endpoint, url: [host: "localhost"], secret_key_base: "3KpMz5Dsmzm2+40c8Urp8UC0N95fFWvsHudtIUHjTv2yGsikjN3wIHPNPi3e+4xi", - render_errors: [view: SafiraWeb.ErrorView, accepts: ~w(json)], + render_errors: [view: SafiraWeb.ErrorJSON, accepts: ~w(json)], pubsub_server: Safira.PubSub config :safira, SafiraWeb.CORS, diff --git a/lib/safira_web/controllers/attendee_json.ex b/lib/safira_web/controllers/attendee_json.ex index 697745ab..78041afd 100644 --- a/lib/safira_web/controllers/attendee_json.ex +++ b/lib/safira_web/controllers/attendee_json.ex @@ -31,6 +31,7 @@ defmodule SafiraWeb.AttendeeJSON do nickname: at.nickname, name: at.name, avatar: Avatar.url({at.avatar, at}, :original), + course: at.course_id, cv: CV.url({at.cv, at}, :original), badges: for(b <- at.badges, do: BadgeJSON.badge(%{badge: b})), badge_count: at.badge_count, @@ -47,6 +48,7 @@ defmodule SafiraWeb.AttendeeJSON do nickname: at.nickname, name: at.name, avatar: Avatar.url({at.avatar, at}, :original), + course: at.course_id, cv: CV.url({at.cv, at}, :original), badges: for(b <- at.badges, do: BadgeJSON.badge(%{badge: b})), badge_count: at.badge_count, @@ -68,12 +70,13 @@ defmodule SafiraWeb.AttendeeJSON do } end - def attendee_simple( %{attendee: at}) do + def attendee_simple(%{attendee: at}) do %{ id: at.id, nickname: at.nickname, name: at.name, avatar: Avatar.url({at.avatar, at}, :original), + course: at.course_id, cv: CV.url({at.cv, at}, :original), token_balance: at.token_balance, entries: at.entries @@ -86,6 +89,7 @@ defmodule SafiraWeb.AttendeeJSON do nickname: at.nickname, name: at.name, avatar: Avatar.url({at.avatar, at}, :original), + course: at.course_id, cv: nil, token_balance: at.token_balance, entries: at.entries diff --git a/lib/safira_web/controllers/badge_json.ex b/lib/safira_web/controllers/badge_json.ex index b1a027d5..e8bce57f 100644 --- a/lib/safira_web/controllers/badge_json.ex +++ b/lib/safira_web/controllers/badge_json.ex @@ -1,5 +1,4 @@ defmodule SafiraWeb.BadgeJSON do - alias SafiraWeb.AttendeeJSON alias Safira.Avatar diff --git a/lib/safira_web/controllers/bonus_json.ex b/lib/safira_web/controllers/bonus_json.ex index 693478e1..b4c501fc 100644 --- a/lib/safira_web/controllers/bonus_json.ex +++ b/lib/safira_web/controllers/bonus_json.ex @@ -1,5 +1,4 @@ defmodule SafiraWeb.BonusJSON do - @token_bonus Application.compile_env!(:safira, :token_bonus) def bonus(changes) do diff --git a/lib/safira_web/controllers/buy_controller.ex b/lib/safira_web/controllers/buy_controller.ex index d3bc1d7e..669e7cf2 100644 --- a/lib/safira_web/controllers/buy_controller.ex +++ b/lib/safira_web/controllers/buy_controller.ex @@ -48,4 +48,8 @@ defmodule SafiraWeb.BuyController do end end end + + def render(template, _assigns) do + %{errors: %{detail: Phoenix.Controller.status_message_from_template(template)}} + end end diff --git a/lib/safira_web/views/error_helpers.ex b/lib/safira_web/controllers/error_json.ex similarity index 61% rename from lib/safira_web/views/error_helpers.ex rename to lib/safira_web/controllers/error_json.ex index cda5b80e..0d4c849e 100644 --- a/lib/safira_web/views/error_helpers.ex +++ b/lib/safira_web/controllers/error_json.ex @@ -1,18 +1,5 @@ -defmodule SafiraWeb.ErrorHelpers do - @moduledoc """ - Conveniences for translating and building error messages. - """ - - use Phoenix.HTML - - @doc """ - Generates tag for inlined form input errors. - """ - def error_tag(form, field) do - Enum.map(Keyword.get_values(form.errors, field), fn error -> - content_tag(:span, translate_error(error), class: "help-block") - end) - end +defmodule SafiraWeb.ErrorJSON do + @moduledoc false @doc """ Translates an error message using gettext. @@ -41,4 +28,28 @@ defmodule SafiraWeb.ErrorHelpers do Gettext.dgettext(SafiraWeb.Gettext, "errors", msg, opts) end end + + @doc """ + Traverses and translates changeset errors. + + See `Ecto.Changeset.traverse_errors/2` and + `SafiraWeb.ErrorHelpers.translate_error/1` for more details. + """ + def translate_errors(changeset) do + Ecto.Changeset.traverse_errors(changeset, &translate_error/1) + end + + def error(%{changeset: changeset}) do + # When encoded, the changeset returns its errors + # as a JSON object. So we just pass it forward. + %{errors: translate_errors(changeset)} + end + + def not_found(_) do + %{error: "Not found"} + end + + def render(template, _assigns) do + %{errors: %{detail: Phoenix.Controller.status_message_from_template(template)}} + end end diff --git a/lib/safira_web/controllers/fallback_controller.ex b/lib/safira_web/controllers/fallback_controller.ex index a773ff2d..deb56539 100644 --- a/lib/safira_web/controllers/fallback_controller.ex +++ b/lib/safira_web/controllers/fallback_controller.ex @@ -6,6 +6,8 @@ defmodule SafiraWeb.FallbackController do """ use SafiraWeb, :controller + alias SafiraWeb.ErrorJSON + def call(conn, {:error, :register_error}) do conn |> put_status(:bad_request) @@ -32,14 +34,19 @@ defmodule SafiraWeb.FallbackController do def call(conn, {:error, %Ecto.Changeset{} = changeset}) do conn + |> put_view(json: ErrorJSON) |> put_status(:unprocessable_entity) - |> render(SafiraWeb.ChangesetView, "error.json", changeset: changeset) + |> render(:error, changeset: changeset) end def call(conn, {:error, :not_found}) do + require Logger + Logger.warn("BATATA") + conn |> put_status(:not_found) - |> render(SafiraWeb.ErrorView, :"404") + |> put_view(json: ErrorJSON) + |> render(:not_found) end def call(conn, {:error, :no_permission}) do diff --git a/lib/safira_web/controllers/redeemable_json.ex b/lib/safira_web/controllers/redeemable_json.ex index 585af637..e3cb7d3f 100644 --- a/lib/safira_web/controllers/redeemable_json.ex +++ b/lib/safira_web/controllers/redeemable_json.ex @@ -1,5 +1,4 @@ defmodule SafiraWeb.RedeemableJSON do - alias Safira.Avatar def index(%{redeemables: redeemables}) do diff --git a/lib/safira_web/views/admin/attendee_view.ex b/lib/safira_web/views/admin/attendee_view.ex deleted file mode 100644 index f93b3eae..00000000 --- a/lib/safira_web/views/admin/attendee_view.ex +++ /dev/null @@ -1,6 +0,0 @@ -defmodule SafiraWeb.Admin.AttendeeView do - use SafiraWeb, :view - - import Torch.TableView - import Torch.FilterView -end diff --git a/lib/safira_web/views/admin/badge_view.ex b/lib/safira_web/views/admin/badge_view.ex deleted file mode 100644 index df03a83a..00000000 --- a/lib/safira_web/views/admin/badge_view.ex +++ /dev/null @@ -1,6 +0,0 @@ -defmodule SafiraWeb.Admin.BadgeView do - use SafiraWeb, :view - - import Torch.TableView - import Torch.FilterView -end diff --git a/lib/safira_web/views/admin/company_view.ex b/lib/safira_web/views/admin/company_view.ex deleted file mode 100644 index f94b0418..00000000 --- a/lib/safira_web/views/admin/company_view.ex +++ /dev/null @@ -1,6 +0,0 @@ -defmodule SafiraWeb.Admin.CompanyView do - use SafiraWeb, :view - - import Torch.TableView - import Torch.FilterView -end diff --git a/lib/safira_web/views/admin/redeem_view.ex b/lib/safira_web/views/admin/redeem_view.ex deleted file mode 100644 index a011591b..00000000 --- a/lib/safira_web/views/admin/redeem_view.ex +++ /dev/null @@ -1,6 +0,0 @@ -defmodule SafiraWeb.Admin.RedeemView do - use SafiraWeb, :view - - import Torch.TableView - import Torch.FilterView -end diff --git a/lib/safira_web/views/admin/referral_view.ex b/lib/safira_web/views/admin/referral_view.ex deleted file mode 100644 index 92899ef4..00000000 --- a/lib/safira_web/views/admin/referral_view.ex +++ /dev/null @@ -1,6 +0,0 @@ -defmodule SafiraWeb.Admin.ReferralView do - use SafiraWeb, :view - - import Torch.TableView - import Torch.FilterView -end diff --git a/lib/safira_web/views/admin/staff_view.ex b/lib/safira_web/views/admin/staff_view.ex deleted file mode 100644 index da0ab0b4..00000000 --- a/lib/safira_web/views/admin/staff_view.ex +++ /dev/null @@ -1,6 +0,0 @@ -defmodule SafiraWeb.Admin.StaffView do - use SafiraWeb, :view - - import Torch.TableView - import Torch.FilterView -end diff --git a/lib/safira_web/views/attendee_view.ex b/lib/safira_web/views/attendee_view.ex deleted file mode 100644 index 3cb05573..00000000 --- a/lib/safira_web/views/attendee_view.ex +++ /dev/null @@ -1,97 +0,0 @@ -defmodule SafiraWeb.AttendeeView do - use SafiraWeb, :view - - alias Safira.Avatar - alias Safira.CV - alias SafiraWeb.AttendeeView - - def render("index.json", %{attendees: attendees}) do - %{data: render_many(attendees, AttendeeView, "attendees.json")} - end - - def render("show.json", %{attendee: attendee}) do - %{data: render_one(attendee, AttendeeView, "attendee.json")} - end - - def render("show_simple.json", %{attendee: attendee}) do - %{data: render_one(attendee, AttendeeView, "attendee_simple.json")} - end - - def render("staff_show.json", %{attendee: attendee}) do - %{data: render_one(attendee, AttendeeView, "staff_attendee.json")} - end - - def render("attendee.json", %{attendee: attendee}) do - %{ - id: attendee.id, - nickname: attendee.nickname, - name: attendee.name, - course: attendee.course_id, - avatar: Avatar.url({attendee.avatar, attendee}, :original), - cv: CV.url({attendee.cv, attendee}, :original), - badges: render_many(attendee.badges, SafiraWeb.BadgeView, "badge.json"), - badge_count: attendee.badge_count, - token_balance: attendee.token_balance, - prizes: render_many(attendee.prizes, SafiraWeb.PrizeView, "prize_attendee.json"), - entries: attendee.entries, - redeemables: - render_many(attendee.redeemables, SafiraWeb.RedeemableView, "my_redeemables.json") - } - end - - def render("attendees.json", %{attendee: attendee}) do - %{ - id: attendee.id, - nickname: attendee.nickname, - name: attendee.name, - course: attendee.course_id, - avatar: Avatar.url({attendee.avatar, attendee}, :original), - cv: CV.url({attendee.cv, attendee}, :original), - badges: render_many(attendee.badges, SafiraWeb.BadgeView, "badge.json"), - badge_count: attendee.badge_count, - token_balance: attendee.token_balance, - # prizes: render_many(attendee.prizes, SafiraWeb.PrizeView, "prize.json"), - entries: attendee.entries - # redeemables: render_many(attendee.redeemables, SafiraWeb.RedeemableView, "my_redeemables.json") - } - end - - def render("staff_attendee.json", %{attendee: attendee}) do - %{ - id: attendee.id, - nickname: attendee.nickname, - name: attendee.name, - email: attendee.user.email, - avatar: Avatar.url({attendee.avatar, attendee}, :original), - cv: CV.url({attendee.cv, attendee}, :original), - badges: render_many(attendee.badges, SafiraWeb.BadgeView, "badge.json"), - badge_count: attendee.badge_count - } - end - - def render("attendee_simple.json", %{attendee: attendee}) do - %{ - id: attendee.id, - nickname: attendee.nickname, - name: attendee.name, - course: attendee.course_id, - avatar: Avatar.url({attendee.avatar, attendee}, :original), - cv: CV.url({attendee.cv, attendee}, :original), - token_balance: attendee.token_balance, - entries: attendee.entries - } - end - - def render("attendee_no_cv.json", %{attendee: attendee}) do - %{ - id: attendee.id, - nickname: attendee.nickname, - name: attendee.name, - course: attendee.course_id, - avatar: Avatar.url({attendee.avatar, attendee}, :original), - cv: nil, - token_balance: attendee.token_balance, - entries: attendee.entries - } - end -end diff --git a/lib/safira_web/views/changeset_view.ex b/lib/safira_web/views/changeset_view.ex deleted file mode 100644 index 76d4d215..00000000 --- a/lib/safira_web/views/changeset_view.ex +++ /dev/null @@ -1,19 +0,0 @@ -defmodule SafiraWeb.ChangesetView do - use SafiraWeb, :view - - @doc """ - Traverses and translates changeset errors. - - See `Ecto.Changeset.traverse_errors/2` and - `SafiraWeb.ErrorHelpers.translate_error/1` for more details. - """ - def translate_errors(changeset) do - Ecto.Changeset.traverse_errors(changeset, &translate_error/1) - end - - def render("error.json", %{changeset: changeset}) do - # When encoded, the changeset returns its errors - # as a JSON object. So we just pass it forward. - %{errors: translate_errors(changeset)} - end -end diff --git a/lib/safira_web/views/error_view.ex b/lib/safira_web/views/error_view.ex deleted file mode 100644 index 166ca31c..00000000 --- a/lib/safira_web/views/error_view.ex +++ /dev/null @@ -1,25 +0,0 @@ -defmodule SafiraWeb.ErrorView do - use SafiraWeb, :view - - # If you want to customize a particular status code - # for a certain format, you may uncomment below. - # def render("500.json", _assigns) do - # %{errors: %{detail: "Internal Server Error"}} - # end - - # By default, Phoenix returns the status message from - # the template name. For example, "404.json" becomes - # "Not Found". - - def render("404.json", _assigns) do - %{errors: %{detail: "Endpoint Not Found"}} - end - - def render("500.json", _assigns) do - %{errors: %{detail: "Internal Server Error"}} - end - - def template_not_found(template, _assigns) do - %{errors: %{detail: Phoenix.Controller.status_message_from_template(template)}} - end -end diff --git a/lib/safira_web/views/layout_view.ex b/lib/safira_web/views/layout_view.ex deleted file mode 100644 index b66e4a48..00000000 --- a/lib/safira_web/views/layout_view.ex +++ /dev/null @@ -1,3 +0,0 @@ -defmodule SafiraWeb.LayoutView do - use SafiraWeb, :view -end diff --git a/lib/safira_web/views/pow/registration_view.ex b/lib/safira_web/views/pow/registration_view.ex deleted file mode 100644 index 7fd64f8f..00000000 --- a/lib/safira_web/views/pow/registration_view.ex +++ /dev/null @@ -1,3 +0,0 @@ -defmodule SafiraWeb.Pow.RegistrationView do - use SafiraWeb, :view -end diff --git a/lib/safira_web/views/pow/session_view.ex b/lib/safira_web/views/pow/session_view.ex deleted file mode 100644 index 278d3574..00000000 --- a/lib/safira_web/views/pow/session_view.ex +++ /dev/null @@ -1,3 +0,0 @@ -defmodule SafiraWeb.Pow.SessionView do - use SafiraWeb, :view -end diff --git a/lib/safira_web/views/prize_view.ex b/lib/safira_web/views/prize_view.ex deleted file mode 100644 index 84b23f6d..00000000 --- a/lib/safira_web/views/prize_view.ex +++ /dev/null @@ -1,42 +0,0 @@ -defmodule SafiraWeb.PrizeView do - use SafiraWeb, :view - - alias Safira.Avatar - alias SafiraWeb.PrizeView - - def render("index.json", %{prizes: prizes}) do - %{data: render_many(prizes, PrizeView, "prize_show.json")} - end - - def render("show.json", %{prize: prize}) do - %{data: render_one(prize, PrizeView, "prize_show.json")} - end - - def render("prize.json", %{prize: prize}) do - %{ - id: prize.id, - name: prize.name, - avatar: Avatar.url({prize.avatar, prize}, :original) - } - end - - def render("prize_attendee.json", %{prize: prize}) do - %{ - id: prize.id, - name: prize.name, - avatar: Avatar.url({prize.avatar, prize}, :original), - not_redeemed: prize.not_redeemed, - is_redeemable: prize.is_redeemable - } - end - - def render("prize_show.json", %{prize: prize}) do - %{ - id: prize.id, - name: prize.name, - avatar: Avatar.url({prize.avatar, prize}, :original), - max_amount_per_attendee: prize.max_amount_per_attendee, - stock: prize.stock - } - end -end diff --git a/test/safira_web/views/error_view_test.exs b/test/safira_web/views/error_view_test.exs deleted file mode 100644 index 3f297074..00000000 --- a/test/safira_web/views/error_view_test.exs +++ /dev/null @@ -1,16 +0,0 @@ -defmodule SafiraWeb.ErrorViewTest do - use SafiraWeb.ConnCase, async: true - - # Bring render/3 and render_to_string/3 for testing custom views - import Phoenix.View - - test "renders 404.json" do - assert render(SafiraWeb.ErrorView, "404.json", []) == - %{errors: %{detail: "Endpoint Not Found"}} - end - - test "renders 500.json" do - assert render(SafiraWeb.ErrorView, "500.json", []) == - %{errors: %{detail: "Internal Server Error"}} - end -end From 5223e7268e0b83fa405eb195abc6bdecbcab6a96 Mon Sep 17 00:00:00 2001 From: Rui Oliveira Date: Sun, 10 Sep 2023 10:30:49 +0100 Subject: [PATCH 15/19] build: fix lint errors --- lib/safira_web/controllers/badge_json.ex | 4 +++- lib/safira_web/controllers/bonus_json.ex | 2 ++ lib/safira_web/controllers/prize_json.ex | 2 ++ lib/safira_web/controllers/redeemable_json.ex | 2 ++ 4 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/safira_web/controllers/badge_json.ex b/lib/safira_web/controllers/badge_json.ex index e8bce57f..c7880131 100644 --- a/lib/safira_web/controllers/badge_json.ex +++ b/lib/safira_web/controllers/badge_json.ex @@ -1,6 +1,8 @@ defmodule SafiraWeb.BadgeJSON do - alias SafiraWeb.AttendeeJSON + @moduledoc false + alias Safira.Avatar + alias SafiraWeb.AttendeeJSON def index(%{badges: badges}) do %{data: for(b <- badges, do: badge(%{badge: b}))} diff --git a/lib/safira_web/controllers/bonus_json.ex b/lib/safira_web/controllers/bonus_json.ex index b4c501fc..21348c8c 100644 --- a/lib/safira_web/controllers/bonus_json.ex +++ b/lib/safira_web/controllers/bonus_json.ex @@ -1,4 +1,6 @@ defmodule SafiraWeb.BonusJSON do + @moduledoc false + @token_bonus Application.compile_env!(:safira, :token_bonus) def bonus(changes) do diff --git a/lib/safira_web/controllers/prize_json.ex b/lib/safira_web/controllers/prize_json.ex index 02ba4049..9c4ad972 100644 --- a/lib/safira_web/controllers/prize_json.ex +++ b/lib/safira_web/controllers/prize_json.ex @@ -1,4 +1,6 @@ defmodule SafiraWeb.PrizeJSON do + @moduledoc false + alias Safira.Avatar def index(%{prizes: prizes}) do diff --git a/lib/safira_web/controllers/redeemable_json.ex b/lib/safira_web/controllers/redeemable_json.ex index e3cb7d3f..14fe5fde 100644 --- a/lib/safira_web/controllers/redeemable_json.ex +++ b/lib/safira_web/controllers/redeemable_json.ex @@ -1,4 +1,6 @@ defmodule SafiraWeb.RedeemableJSON do + @moduledoc false + alias Safira.Avatar def index(%{redeemables: redeemables}) do From 17f77fd1b9a89d1aca905d30584481bb0aa61645 Mon Sep 17 00:00:00 2001 From: Rui Oliveira Date: Sat, 16 Sep 2023 19:47:01 +0100 Subject: [PATCH 16/19] fix: remove debug print --- lib/safira_web/controllers/fallback_controller.ex | 3 --- 1 file changed, 3 deletions(-) diff --git a/lib/safira_web/controllers/fallback_controller.ex b/lib/safira_web/controllers/fallback_controller.ex index deb56539..81bce9b6 100644 --- a/lib/safira_web/controllers/fallback_controller.ex +++ b/lib/safira_web/controllers/fallback_controller.ex @@ -40,9 +40,6 @@ defmodule SafiraWeb.FallbackController do end def call(conn, {:error, :not_found}) do - require Logger - Logger.warn("BATATA") - conn |> put_status(:not_found) |> put_view(json: ErrorJSON) From 2c4c76c2d5324c64e085bada4e66e68451b2a9df Mon Sep 17 00:00:00 2001 From: Rui Lopes Date: Sun, 5 Nov 2023 13:44:42 +0000 Subject: [PATCH 17/19] refactor: filesystem --- lib/safira_web/controllers/{ => attendee}/attendee_controller.ex | 0 lib/safira_web/controllers/{ => attendee}/attendee_json.ex | 0 lib/safira_web/controllers/{ => auth}/auth_controller.ex | 0 lib/safira_web/controllers/{ => auth}/auth_json.ex | 0 lib/safira_web/controllers/{ => badge}/badge_controller.ex | 0 lib/safira_web/controllers/{ => badge}/badge_json.ex | 0 lib/safira_web/controllers/{ => bonus}/bonus_controller.ex | 0 lib/safira_web/controllers/{ => bonus}/bonus_json.ex | 0 lib/safira_web/controllers/{ => buy}/buy_controller.ex | 0 lib/safira_web/controllers/{ => company}/company_controller.ex | 0 lib/safira_web/controllers/{ => company}/company_json.ex | 0 lib/safira_web/controllers/{ => cv}/cv_controller.ex | 0 .../controllers/{ => deliver_prize}/deliver_prize_controller.ex | 0 .../controllers/{ => deliver_prize}/deliver_prize_json.ex | 0 .../{ => deliver_redeemable}/deliver_redeemable_controller.ex | 0 .../{ => deliver_redeemable}/deliver_redeemable_json.ex | 0 .../controllers/{ => discord}/discord_association_controller.ex | 0 .../controllers/{ => leaderboard}/leaderboard_controller.ex | 0 lib/safira_web/controllers/{ => leaderboard}/leaderboard_json.ex | 0 lib/safira_web/controllers/{ => password}/password_controller.ex | 0 lib/safira_web/controllers/{ => password}/password_json.ex | 0 lib/safira_web/controllers/{ => prize}/prize_controller.ex | 0 lib/safira_web/controllers/{ => prize}/prize_json.ex | 0 lib/safira_web/controllers/{ => redeem}/redeem_controller.ex | 0 .../controllers/{ => redeemable}/redeemable_controller.ex | 0 lib/safira_web/controllers/{ => redeemable}/redeemable_json.ex | 0 lib/safira_web/controllers/{ => referral}/referral_controller.ex | 0 lib/safira_web/controllers/{ => roulette}/roulette_controller.ex | 0 lib/safira_web/controllers/{ => roulette}/roulette_json.ex | 0 .../controllers/{ => spotlight}/spotlight_controller.ex | 0 lib/safira_web/controllers/{ => user}/user_controller.ex | 0 lib/safira_web/controllers/{ => user}/user_json.ex | 0 .../controllers/{ => attendee}/attendee_controller_test.exs | 0 test/safira_web/controllers/{ => auth}/auth_controller_test.exs | 0 test/safira_web/controllers/{ => badge}/badge_controller_test.exs | 0 test/safira_web/controllers/{ => bonus}/bonus_controller_test.exs | 0 test/safira_web/controllers/{ => buy}/buy_controller_test.exs | 0 .../controllers/{ => company}/company_controller_test.exs | 0 test/safira_web/controllers/{ => cv}/cv_controller_test.exs | 0 .../{ => deliver_prize}/deliver_prize_controller_test.exs | 0 .../deliver_redeemable_controller_test.exs | 0 .../controllers/{ => leaderboard}/leaderboard_controller_test.exs | 0 .../controllers/{ => password}/password_controller_test.exs | 0 test/safira_web/controllers/{ => prize}/prize_controller_test.exs | 0 .../controllers/{ => redeem}/redeem_controller_test.exs | 0 .../controllers/{ => redeemable}/redeemable_controller_test.exs | 0 .../controllers/{ => referral}/referral_controller_test.exs | 0 .../controllers/{ => roulette}/roulette_controller_test.exs | 0 48 files changed, 0 insertions(+), 0 deletions(-) rename lib/safira_web/controllers/{ => attendee}/attendee_controller.ex (100%) rename lib/safira_web/controllers/{ => attendee}/attendee_json.ex (100%) rename lib/safira_web/controllers/{ => auth}/auth_controller.ex (100%) rename lib/safira_web/controllers/{ => auth}/auth_json.ex (100%) rename lib/safira_web/controllers/{ => badge}/badge_controller.ex (100%) rename lib/safira_web/controllers/{ => badge}/badge_json.ex (100%) rename lib/safira_web/controllers/{ => bonus}/bonus_controller.ex (100%) rename lib/safira_web/controllers/{ => bonus}/bonus_json.ex (100%) rename lib/safira_web/controllers/{ => buy}/buy_controller.ex (100%) rename lib/safira_web/controllers/{ => company}/company_controller.ex (100%) rename lib/safira_web/controllers/{ => company}/company_json.ex (100%) rename lib/safira_web/controllers/{ => cv}/cv_controller.ex (100%) rename lib/safira_web/controllers/{ => deliver_prize}/deliver_prize_controller.ex (100%) rename lib/safira_web/controllers/{ => deliver_prize}/deliver_prize_json.ex (100%) rename lib/safira_web/controllers/{ => deliver_redeemable}/deliver_redeemable_controller.ex (100%) rename lib/safira_web/controllers/{ => deliver_redeemable}/deliver_redeemable_json.ex (100%) rename lib/safira_web/controllers/{ => discord}/discord_association_controller.ex (100%) rename lib/safira_web/controllers/{ => leaderboard}/leaderboard_controller.ex (100%) rename lib/safira_web/controllers/{ => leaderboard}/leaderboard_json.ex (100%) rename lib/safira_web/controllers/{ => password}/password_controller.ex (100%) rename lib/safira_web/controllers/{ => password}/password_json.ex (100%) rename lib/safira_web/controllers/{ => prize}/prize_controller.ex (100%) rename lib/safira_web/controllers/{ => prize}/prize_json.ex (100%) rename lib/safira_web/controllers/{ => redeem}/redeem_controller.ex (100%) rename lib/safira_web/controllers/{ => redeemable}/redeemable_controller.ex (100%) rename lib/safira_web/controllers/{ => redeemable}/redeemable_json.ex (100%) rename lib/safira_web/controllers/{ => referral}/referral_controller.ex (100%) rename lib/safira_web/controllers/{ => roulette}/roulette_controller.ex (100%) rename lib/safira_web/controllers/{ => roulette}/roulette_json.ex (100%) rename lib/safira_web/controllers/{ => spotlight}/spotlight_controller.ex (100%) rename lib/safira_web/controllers/{ => user}/user_controller.ex (100%) rename lib/safira_web/controllers/{ => user}/user_json.ex (100%) rename test/safira_web/controllers/{ => attendee}/attendee_controller_test.exs (100%) rename test/safira_web/controllers/{ => auth}/auth_controller_test.exs (100%) rename test/safira_web/controllers/{ => badge}/badge_controller_test.exs (100%) rename test/safira_web/controllers/{ => bonus}/bonus_controller_test.exs (100%) rename test/safira_web/controllers/{ => buy}/buy_controller_test.exs (100%) rename test/safira_web/controllers/{ => company}/company_controller_test.exs (100%) rename test/safira_web/controllers/{ => cv}/cv_controller_test.exs (100%) rename test/safira_web/controllers/{ => deliver_prize}/deliver_prize_controller_test.exs (100%) rename test/safira_web/controllers/{ => deliver_redeemable}/deliver_redeemable_controller_test.exs (100%) rename test/safira_web/controllers/{ => leaderboard}/leaderboard_controller_test.exs (100%) rename test/safira_web/controllers/{ => password}/password_controller_test.exs (100%) rename test/safira_web/controllers/{ => prize}/prize_controller_test.exs (100%) rename test/safira_web/controllers/{ => redeem}/redeem_controller_test.exs (100%) rename test/safira_web/controllers/{ => redeemable}/redeemable_controller_test.exs (100%) rename test/safira_web/controllers/{ => referral}/referral_controller_test.exs (100%) rename test/safira_web/controllers/{ => roulette}/roulette_controller_test.exs (100%) diff --git a/lib/safira_web/controllers/attendee_controller.ex b/lib/safira_web/controllers/attendee/attendee_controller.ex similarity index 100% rename from lib/safira_web/controllers/attendee_controller.ex rename to lib/safira_web/controllers/attendee/attendee_controller.ex diff --git a/lib/safira_web/controllers/attendee_json.ex b/lib/safira_web/controllers/attendee/attendee_json.ex similarity index 100% rename from lib/safira_web/controllers/attendee_json.ex rename to lib/safira_web/controllers/attendee/attendee_json.ex diff --git a/lib/safira_web/controllers/auth_controller.ex b/lib/safira_web/controllers/auth/auth_controller.ex similarity index 100% rename from lib/safira_web/controllers/auth_controller.ex rename to lib/safira_web/controllers/auth/auth_controller.ex diff --git a/lib/safira_web/controllers/auth_json.ex b/lib/safira_web/controllers/auth/auth_json.ex similarity index 100% rename from lib/safira_web/controllers/auth_json.ex rename to lib/safira_web/controllers/auth/auth_json.ex diff --git a/lib/safira_web/controllers/badge_controller.ex b/lib/safira_web/controllers/badge/badge_controller.ex similarity index 100% rename from lib/safira_web/controllers/badge_controller.ex rename to lib/safira_web/controllers/badge/badge_controller.ex diff --git a/lib/safira_web/controllers/badge_json.ex b/lib/safira_web/controllers/badge/badge_json.ex similarity index 100% rename from lib/safira_web/controllers/badge_json.ex rename to lib/safira_web/controllers/badge/badge_json.ex diff --git a/lib/safira_web/controllers/bonus_controller.ex b/lib/safira_web/controllers/bonus/bonus_controller.ex similarity index 100% rename from lib/safira_web/controllers/bonus_controller.ex rename to lib/safira_web/controllers/bonus/bonus_controller.ex diff --git a/lib/safira_web/controllers/bonus_json.ex b/lib/safira_web/controllers/bonus/bonus_json.ex similarity index 100% rename from lib/safira_web/controllers/bonus_json.ex rename to lib/safira_web/controllers/bonus/bonus_json.ex diff --git a/lib/safira_web/controllers/buy_controller.ex b/lib/safira_web/controllers/buy/buy_controller.ex similarity index 100% rename from lib/safira_web/controllers/buy_controller.ex rename to lib/safira_web/controllers/buy/buy_controller.ex diff --git a/lib/safira_web/controllers/company_controller.ex b/lib/safira_web/controllers/company/company_controller.ex similarity index 100% rename from lib/safira_web/controllers/company_controller.ex rename to lib/safira_web/controllers/company/company_controller.ex diff --git a/lib/safira_web/controllers/company_json.ex b/lib/safira_web/controllers/company/company_json.ex similarity index 100% rename from lib/safira_web/controllers/company_json.ex rename to lib/safira_web/controllers/company/company_json.ex diff --git a/lib/safira_web/controllers/cv_controller.ex b/lib/safira_web/controllers/cv/cv_controller.ex similarity index 100% rename from lib/safira_web/controllers/cv_controller.ex rename to lib/safira_web/controllers/cv/cv_controller.ex diff --git a/lib/safira_web/controllers/deliver_prize_controller.ex b/lib/safira_web/controllers/deliver_prize/deliver_prize_controller.ex similarity index 100% rename from lib/safira_web/controllers/deliver_prize_controller.ex rename to lib/safira_web/controllers/deliver_prize/deliver_prize_controller.ex diff --git a/lib/safira_web/controllers/deliver_prize_json.ex b/lib/safira_web/controllers/deliver_prize/deliver_prize_json.ex similarity index 100% rename from lib/safira_web/controllers/deliver_prize_json.ex rename to lib/safira_web/controllers/deliver_prize/deliver_prize_json.ex diff --git a/lib/safira_web/controllers/deliver_redeemable_controller.ex b/lib/safira_web/controllers/deliver_redeemable/deliver_redeemable_controller.ex similarity index 100% rename from lib/safira_web/controllers/deliver_redeemable_controller.ex rename to lib/safira_web/controllers/deliver_redeemable/deliver_redeemable_controller.ex diff --git a/lib/safira_web/controllers/deliver_redeemable_json.ex b/lib/safira_web/controllers/deliver_redeemable/deliver_redeemable_json.ex similarity index 100% rename from lib/safira_web/controllers/deliver_redeemable_json.ex rename to lib/safira_web/controllers/deliver_redeemable/deliver_redeemable_json.ex diff --git a/lib/safira_web/controllers/discord_association_controller.ex b/lib/safira_web/controllers/discord/discord_association_controller.ex similarity index 100% rename from lib/safira_web/controllers/discord_association_controller.ex rename to lib/safira_web/controllers/discord/discord_association_controller.ex diff --git a/lib/safira_web/controllers/leaderboard_controller.ex b/lib/safira_web/controllers/leaderboard/leaderboard_controller.ex similarity index 100% rename from lib/safira_web/controllers/leaderboard_controller.ex rename to lib/safira_web/controllers/leaderboard/leaderboard_controller.ex diff --git a/lib/safira_web/controllers/leaderboard_json.ex b/lib/safira_web/controllers/leaderboard/leaderboard_json.ex similarity index 100% rename from lib/safira_web/controllers/leaderboard_json.ex rename to lib/safira_web/controllers/leaderboard/leaderboard_json.ex diff --git a/lib/safira_web/controllers/password_controller.ex b/lib/safira_web/controllers/password/password_controller.ex similarity index 100% rename from lib/safira_web/controllers/password_controller.ex rename to lib/safira_web/controllers/password/password_controller.ex diff --git a/lib/safira_web/controllers/password_json.ex b/lib/safira_web/controllers/password/password_json.ex similarity index 100% rename from lib/safira_web/controllers/password_json.ex rename to lib/safira_web/controllers/password/password_json.ex diff --git a/lib/safira_web/controllers/prize_controller.ex b/lib/safira_web/controllers/prize/prize_controller.ex similarity index 100% rename from lib/safira_web/controllers/prize_controller.ex rename to lib/safira_web/controllers/prize/prize_controller.ex diff --git a/lib/safira_web/controllers/prize_json.ex b/lib/safira_web/controllers/prize/prize_json.ex similarity index 100% rename from lib/safira_web/controllers/prize_json.ex rename to lib/safira_web/controllers/prize/prize_json.ex diff --git a/lib/safira_web/controllers/redeem_controller.ex b/lib/safira_web/controllers/redeem/redeem_controller.ex similarity index 100% rename from lib/safira_web/controllers/redeem_controller.ex rename to lib/safira_web/controllers/redeem/redeem_controller.ex diff --git a/lib/safira_web/controllers/redeemable_controller.ex b/lib/safira_web/controllers/redeemable/redeemable_controller.ex similarity index 100% rename from lib/safira_web/controllers/redeemable_controller.ex rename to lib/safira_web/controllers/redeemable/redeemable_controller.ex diff --git a/lib/safira_web/controllers/redeemable_json.ex b/lib/safira_web/controllers/redeemable/redeemable_json.ex similarity index 100% rename from lib/safira_web/controllers/redeemable_json.ex rename to lib/safira_web/controllers/redeemable/redeemable_json.ex diff --git a/lib/safira_web/controllers/referral_controller.ex b/lib/safira_web/controllers/referral/referral_controller.ex similarity index 100% rename from lib/safira_web/controllers/referral_controller.ex rename to lib/safira_web/controllers/referral/referral_controller.ex diff --git a/lib/safira_web/controllers/roulette_controller.ex b/lib/safira_web/controllers/roulette/roulette_controller.ex similarity index 100% rename from lib/safira_web/controllers/roulette_controller.ex rename to lib/safira_web/controllers/roulette/roulette_controller.ex diff --git a/lib/safira_web/controllers/roulette_json.ex b/lib/safira_web/controllers/roulette/roulette_json.ex similarity index 100% rename from lib/safira_web/controllers/roulette_json.ex rename to lib/safira_web/controllers/roulette/roulette_json.ex diff --git a/lib/safira_web/controllers/spotlight_controller.ex b/lib/safira_web/controllers/spotlight/spotlight_controller.ex similarity index 100% rename from lib/safira_web/controllers/spotlight_controller.ex rename to lib/safira_web/controllers/spotlight/spotlight_controller.ex diff --git a/lib/safira_web/controllers/user_controller.ex b/lib/safira_web/controllers/user/user_controller.ex similarity index 100% rename from lib/safira_web/controllers/user_controller.ex rename to lib/safira_web/controllers/user/user_controller.ex diff --git a/lib/safira_web/controllers/user_json.ex b/lib/safira_web/controllers/user/user_json.ex similarity index 100% rename from lib/safira_web/controllers/user_json.ex rename to lib/safira_web/controllers/user/user_json.ex diff --git a/test/safira_web/controllers/attendee_controller_test.exs b/test/safira_web/controllers/attendee/attendee_controller_test.exs similarity index 100% rename from test/safira_web/controllers/attendee_controller_test.exs rename to test/safira_web/controllers/attendee/attendee_controller_test.exs diff --git a/test/safira_web/controllers/auth_controller_test.exs b/test/safira_web/controllers/auth/auth_controller_test.exs similarity index 100% rename from test/safira_web/controllers/auth_controller_test.exs rename to test/safira_web/controllers/auth/auth_controller_test.exs diff --git a/test/safira_web/controllers/badge_controller_test.exs b/test/safira_web/controllers/badge/badge_controller_test.exs similarity index 100% rename from test/safira_web/controllers/badge_controller_test.exs rename to test/safira_web/controllers/badge/badge_controller_test.exs diff --git a/test/safira_web/controllers/bonus_controller_test.exs b/test/safira_web/controllers/bonus/bonus_controller_test.exs similarity index 100% rename from test/safira_web/controllers/bonus_controller_test.exs rename to test/safira_web/controllers/bonus/bonus_controller_test.exs diff --git a/test/safira_web/controllers/buy_controller_test.exs b/test/safira_web/controllers/buy/buy_controller_test.exs similarity index 100% rename from test/safira_web/controllers/buy_controller_test.exs rename to test/safira_web/controllers/buy/buy_controller_test.exs diff --git a/test/safira_web/controllers/company_controller_test.exs b/test/safira_web/controllers/company/company_controller_test.exs similarity index 100% rename from test/safira_web/controllers/company_controller_test.exs rename to test/safira_web/controllers/company/company_controller_test.exs diff --git a/test/safira_web/controllers/cv_controller_test.exs b/test/safira_web/controllers/cv/cv_controller_test.exs similarity index 100% rename from test/safira_web/controllers/cv_controller_test.exs rename to test/safira_web/controllers/cv/cv_controller_test.exs diff --git a/test/safira_web/controllers/deliver_prize_controller_test.exs b/test/safira_web/controllers/deliver_prize/deliver_prize_controller_test.exs similarity index 100% rename from test/safira_web/controllers/deliver_prize_controller_test.exs rename to test/safira_web/controllers/deliver_prize/deliver_prize_controller_test.exs diff --git a/test/safira_web/controllers/deliver_redeemable_controller_test.exs b/test/safira_web/controllers/deliver_redeemable/deliver_redeemable_controller_test.exs similarity index 100% rename from test/safira_web/controllers/deliver_redeemable_controller_test.exs rename to test/safira_web/controllers/deliver_redeemable/deliver_redeemable_controller_test.exs diff --git a/test/safira_web/controllers/leaderboard_controller_test.exs b/test/safira_web/controllers/leaderboard/leaderboard_controller_test.exs similarity index 100% rename from test/safira_web/controllers/leaderboard_controller_test.exs rename to test/safira_web/controllers/leaderboard/leaderboard_controller_test.exs diff --git a/test/safira_web/controllers/password_controller_test.exs b/test/safira_web/controllers/password/password_controller_test.exs similarity index 100% rename from test/safira_web/controllers/password_controller_test.exs rename to test/safira_web/controllers/password/password_controller_test.exs diff --git a/test/safira_web/controllers/prize_controller_test.exs b/test/safira_web/controllers/prize/prize_controller_test.exs similarity index 100% rename from test/safira_web/controllers/prize_controller_test.exs rename to test/safira_web/controllers/prize/prize_controller_test.exs diff --git a/test/safira_web/controllers/redeem_controller_test.exs b/test/safira_web/controllers/redeem/redeem_controller_test.exs similarity index 100% rename from test/safira_web/controllers/redeem_controller_test.exs rename to test/safira_web/controllers/redeem/redeem_controller_test.exs diff --git a/test/safira_web/controllers/redeemable_controller_test.exs b/test/safira_web/controllers/redeemable/redeemable_controller_test.exs similarity index 100% rename from test/safira_web/controllers/redeemable_controller_test.exs rename to test/safira_web/controllers/redeemable/redeemable_controller_test.exs diff --git a/test/safira_web/controllers/referral_controller_test.exs b/test/safira_web/controllers/referral/referral_controller_test.exs similarity index 100% rename from test/safira_web/controllers/referral_controller_test.exs rename to test/safira_web/controllers/referral/referral_controller_test.exs diff --git a/test/safira_web/controllers/roulette_controller_test.exs b/test/safira_web/controllers/roulette/roulette_controller_test.exs similarity index 100% rename from test/safira_web/controllers/roulette_controller_test.exs rename to test/safira_web/controllers/roulette/roulette_controller_test.exs From d9d5cbccc322dad34068239afb7bce3195f47d68 Mon Sep 17 00:00:00 2001 From: Rui Oliveira Date: Wed, 29 Nov 2023 16:31:53 +0000 Subject: [PATCH 18/19] fix: variable name --- lib/safira_web/controllers/attendee/attendee_json.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/safira_web/controllers/attendee/attendee_json.ex b/lib/safira_web/controllers/attendee/attendee_json.ex index 78041afd..376f1892 100644 --- a/lib/safira_web/controllers/attendee/attendee_json.ex +++ b/lib/safira_web/controllers/attendee/attendee_json.ex @@ -38,7 +38,7 @@ defmodule SafiraWeb.AttendeeJSON do token_balance: at.token_balance, prizes: for(p <- at.prizes, do: PrizeJSON.prize_attendee(%{prize: p})), entries: at.entries, - redeemables: for(r <- at.redeemables, do: RedeemableJSON.my_readeemables(%{redeemable: r})) + redeemables: for(r <- at.redeemables, do: RedeemableJSON.my_redeemables(%{redeemable: r})) } end From 16499f3e2166a722ce567962fcbf53b68cecbb74 Mon Sep 17 00:00:00 2001 From: Rui Oliveira Date: Sun, 17 Dec 2023 10:51:17 +0000 Subject: [PATCH 19/19] fix: price json --- lib/safira_web/controllers/roulette/roulette_controller.ex | 2 +- lib/safira_web/controllers/roulette/roulette_json.ex | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/safira_web/controllers/roulette/roulette_controller.ex b/lib/safira_web/controllers/roulette/roulette_controller.ex index 4393ecfd..fd5780bc 100644 --- a/lib/safira_web/controllers/roulette/roulette_controller.ex +++ b/lib/safira_web/controllers/roulette/roulette_controller.ex @@ -34,6 +34,6 @@ defmodule SafiraWeb.RouletteController do end def price(conn, _params) do - render(conn, "price.json", price: @price) + render(conn, "price_show.json", price: @price) end end diff --git a/lib/safira_web/controllers/roulette/roulette_json.ex b/lib/safira_web/controllers/roulette/roulette_json.ex index 290b6010..b270edaa 100644 --- a/lib/safira_web/controllers/roulette/roulette_json.ex +++ b/lib/safira_web/controllers/roulette/roulette_json.ex @@ -33,6 +33,10 @@ defmodule SafiraWeb.RouletteJSON do resp end + def price_show(%{price: price}) do + %{price: price} + end + def latest_prizes(%{latest_prizes: latest_prizes}) do %{data: for(p <- latest_prizes, do: latest_prize_show(%{roulette: p}))} end