Skip to content

Commit

Permalink
feat: add course to attendee
Browse files Browse the repository at this point in the history
  • Loading branch information
joaodiaslobo committed Nov 24, 2023
1 parent b6a4d49 commit 0551c80
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 4 deletions.
9 changes: 8 additions & 1 deletion lib/mix/tasks/gen.attendees_with_password.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ defmodule Mix.Tasks.Gen.AttendeesWithPassword do
alias Safira.Accounts

@domain "seium.org"
@courses File.read!("priv/fake/courses.txt") |> String.split("\n")

def run(args) do
cond do
Expand All @@ -28,6 +29,7 @@ defmodule Mix.Tasks.Gen.AttendeesWithPassword do
nickname = "attendee#{n}"
email = Enum.join([nickname, @domain], "@")
password = random_string(8)
course = Enum.random(@courses)

user = %{
"email" => email,
Expand All @@ -36,7 +38,12 @@ defmodule Mix.Tasks.Gen.AttendeesWithPassword do
}

account =

Check warning on line 40 in lib/mix/tasks/gen.attendees_with_password.ex

View workflow job for this annotation

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

variable "account" is unused (if the variable is not meant to be used, prefix it with an underscore)
Accounts.create_attendee(%{"name" => nickname, "nickname" => nickname, "user" => user})
Accounts.create_attendee(%{
"name" => nickname,
"nickname" => nickname,
"course" => course,
"user" => user
})
|> elem(1)

IO.puts("#{email}:#{password}")
Expand Down
7 changes: 4 additions & 3 deletions lib/safira/accounts/attendee.ex
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ defmodule Safira.Accounts.Attendee do
field :nickname, :string
field :avatar, Safira.Avatar.Type
field :name, :string
field :course, :string
field :token_balance, :integer, default: 0
field :entries, :integer, default: 0
field :discord_association_code, Ecto.UUID, autogenerate: true
Expand All @@ -49,7 +50,7 @@ defmodule Safira.Accounts.Attendee do

def changeset(attendee, attrs) do
attendee
|> cast(attrs, [:name, :nickname, :user_id])
|> cast(attrs, [:name, :nickname, :user_id, :course])
|> cast_attachments(attrs, [:avatar, :cv])
|> cast_assoc(:user)
|> validate_required([:name, :nickname])
Expand All @@ -59,7 +60,7 @@ defmodule Safira.Accounts.Attendee do

def update_changeset_sign_up(attendee, attrs) do
attendee
|> cast(attrs, [:name, :nickname, :user_id])
|> cast(attrs, [:name, :nickname, :user_id, :course])
|> cast_attachments(attrs, [:avatar, :cv])
|> cast_assoc(:user)
|> validate_required([:name, :nickname])
Expand All @@ -69,7 +70,7 @@ defmodule Safira.Accounts.Attendee do

def update_changeset(attendee, attrs) do
attendee
|> cast(attrs, [:nickname])
|> cast(attrs, [:nickname, :course])
|> cast_attachments(attrs, [:avatar, :cv])
|> validate_required([:nickname])
|> validate_format(:nickname, @nickname_regex)
Expand Down
4 changes: 4 additions & 0 deletions lib/safira_web/views/attendee_view.ex
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ defmodule SafiraWeb.AttendeeView do
id: attendee.id,
nickname: attendee.nickname,
name: attendee.name,
course: attendee.course,
avatar: Avatar.url({attendee.avatar, attendee}, :original),
cv: CV.url({attendee.cv, attendee}, :original),
badges: render_many(attendee.badges, SafiraWeb.BadgeView, "badge.json"),
Expand All @@ -43,6 +44,7 @@ defmodule SafiraWeb.AttendeeView do
id: attendee.id,
nickname: attendee.nickname,
name: attendee.name,
course: attendee.course,
avatar: Avatar.url({attendee.avatar, attendee}, :original),
cv: CV.url({attendee.cv, attendee}, :original),
badges: render_many(attendee.badges, SafiraWeb.BadgeView, "badge.json"),
Expand Down Expand Up @@ -72,6 +74,7 @@ defmodule SafiraWeb.AttendeeView do
id: attendee.id,
nickname: attendee.nickname,
name: attendee.name,
course: attendee.course,
avatar: Avatar.url({attendee.avatar, attendee}, :original),
cv: CV.url({attendee.cv, attendee}, :original),
token_balance: attendee.token_balance,
Expand All @@ -84,6 +87,7 @@ defmodule SafiraWeb.AttendeeView do
id: attendee.id,
nickname: attendee.nickname,
name: attendee.name,
course: attendee.course,
avatar: Avatar.url({attendee.avatar, attendee}, :original),
cv: nil,
token_balance: attendee.token_balance,
Expand Down
59 changes: 59 additions & 0 deletions priv/fake/courses.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
Administração Pública
Arqueologia
Artes Visuais
Biologia Aplicada
Biologia e Geologia
Bioquímica
Ciência de Dados
Ciências da Educação
Ciência Política
Ciências da Computação
Ciências da Comunicação
Ciências do Ambiente
Contabilidade
Criminologia e Justiça Criminal
Design de Produto
Design e Marketing de Moda
Direito
Economia
Educação
Educação Básica
Enfermagem
Engenharia Aeroespacial
Engenharia Biomédica
Engenharia Civil
Engenharia de Materiais
Engenharia de Polímeros
Engenharia de Telecomunicações e Informática
Engenharia e Gestão de Sistemas de Informação
Engenharia e Gestão Industrial
Engenharia Eletrónica Industrial e Computadores
Engenharia Física
Engenharia Informática
Engenharia Mecânica
Engenharia Química e Biológica
Engenharia Têxtil
Estatística Aplicada
Estudos Culturais
Estudos Orientais: Estudos Chineses e Japoneses
Estudos Portugueses
Filosofia
Física
Geografia e Planeamento
Geologia
Gestão
História
Línguas Aplicadas
Línguas e Literaturas Europeias
Medicina
Marketing
Matemática
Música
Negócios Internacionais
Optometria e Ciências da Visão
Proteção Civil e Gestão do Território
Psicologia
Química
Relações Internacionais
Sociologia
Teatro
1 change: 1 addition & 0 deletions priv/repo/migrations/20180704191725_create_attendees.exs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ defmodule Safira.Repo.Migrations.CreateAttendees do
add :uuid, :string
add :nickname, :string
add :user_id, references(:users, on_delete: :delete_all)
add :course, :string

timestamps()
end
Expand Down
3 changes: 3 additions & 0 deletions test/safira_web/controllers/attendee_controller_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ defmodule SafiraWeb.AttendeeControllerTest do
"id" => attendee.id,
"name" => attendee.name,
"nickname" => attendee.nickname,
"course" => attendee.course,
"token_balance" => 0,
"badges" => [],
"badge_count" => 0
Expand Down Expand Up @@ -137,6 +138,7 @@ defmodule SafiraWeb.AttendeeControllerTest do
"id" => attendee.id,
"name" => attendee.name,
"nickname" => attendee.nickname,
"course" => attendee.course,
"token_balance" => 0,
"badges" => [],
"badge_count" => 0,
Expand Down Expand Up @@ -180,6 +182,7 @@ defmodule SafiraWeb.AttendeeControllerTest do
"id" => attendee.id,
"name" => attendee.name,
"nickname" => "john_doe123",
"course" => attendee.course,
"token_balance" => 0
}

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 @@ -113,6 +113,7 @@ defmodule SafiraWeb.CompanyControllerTest do
"id" => attendee.id,
"nickname" => attendee.nickname,
"name" => attendee.name,
"course" => attendee.course,
"avatar" => nil,
"cv" => nil,
"token_balance" => attendee.token_balance,
Expand Down Expand Up @@ -143,6 +144,7 @@ defmodule SafiraWeb.CompanyControllerTest do
"id" => attendee1.id,
"nickname" => attendee1.nickname,
"name" => attendee1.name,
"course" => attendee1.course,
"avatar" => nil,
"cv" => nil,
"token_balance" => attendee1.token_balance,
Expand All @@ -152,6 +154,7 @@ defmodule SafiraWeb.CompanyControllerTest do
"id" => attendee2.id,
"nickname" => attendee2.nickname,
"name" => attendee2.name,
"course" => attendee2.course,
"avatar" => nil,
"cv" => nil,
"token_balance" => attendee2.token_balance,
Expand Down Expand Up @@ -192,6 +195,7 @@ defmodule SafiraWeb.CompanyControllerTest do
"id" => attendee1.id,
"nickname" => attendee1.nickname,
"name" => attendee1.name,
"course" => attendee1.course,
"avatar" => nil,
"cv" => nil,
"token_balance" => attendee1.token_balance,
Expand Down

0 comments on commit 0551c80

Please sign in to comment.