diff --git a/lib/code_corps_web/controllers/project_skill_controller.ex b/lib/code_corps_web/controllers/project_skill_controller.ex index cd0d45bf8..d02cdfbdc 100644 --- a/lib/code_corps_web/controllers/project_skill_controller.ex +++ b/lib/code_corps_web/controllers/project_skill_controller.ex @@ -10,14 +10,14 @@ defmodule CodeCorpsWeb.ProjectSkillController do @spec index(Conn.t, map) :: Conn.t def index(%Conn{} = conn, %{} = params) do - with project_skills <- ProjectSkill |> Query.id_filter(params) |> Repo.all do + with project_skills <- ProjectSkill |> Query.id_filter(params) |> Repo.all |> preload() do conn |> render("index.json-api", data: project_skills) end end @spec show(Conn.t, map) :: Conn.t def show(%Conn{} = conn, %{"id" => id}) do - with %ProjectSkill{} = project_skill <- ProjectSkill |> Repo.get(id) do + with %ProjectSkill{} = project_skill <- ProjectSkill |> Repo.get(id) |> preload() do conn |> render("show.json-api", data: project_skill) end end @@ -26,8 +26,9 @@ defmodule CodeCorpsWeb.ProjectSkillController do def create(%Conn{} = conn, %{} = params) do with %User{} = current_user <- conn |> Guardian.Plug.current_resource, {:ok, :authorized} <- current_user |> Policy.authorize(:create, %ProjectSkill{}, params), - {:ok, %ProjectSkill{} = project_skill} <- %ProjectSkill{} |> ProjectSkill.create_changeset(params) |> Repo.insert do - + {:ok, %ProjectSkill{} = project_skill} <- %ProjectSkill{} |> ProjectSkill.create_changeset(params) |> Repo.insert(), + project_skill <- preload(project_skill) + do current_user.id |> SegmentTracker.track("Added Project Skill", project_skill) conn |> put_status(:created) |> render("show.json-api", data: project_skill) end @@ -44,4 +45,12 @@ defmodule CodeCorpsWeb.ProjectSkillController do conn |> Conn.assign(:project_skill, project_skill) |> send_resp(:no_content, "") end end + + @preloads [ + :skill + ] + + def preload(data) do + Repo.preload(data, @preloads) + end end diff --git a/lib/code_corps_web/controllers/task_controller.ex b/lib/code_corps_web/controllers/task_controller.ex index e5954bbb2..d7f2712cc 100644 --- a/lib/code_corps_web/controllers/task_controller.ex +++ b/lib/code_corps_web/controllers/task_controller.ex @@ -62,7 +62,7 @@ defmodule CodeCorpsWeb.TaskController do end end - @preloads [:comments, :github_pull_request, :task_skills, :user_task] + @preloads [:comments, :github_pull_request, :task_skills, :user, [user_task: :user]] def preload(data) do timing("TaskController", "preload") do diff --git a/lib/code_corps_web/views/project_view.ex b/lib/code_corps_web/views/project_view.ex index 009491d1c..6ce94d29b 100644 --- a/lib/code_corps_web/views/project_view.ex +++ b/lib/code_corps_web/views/project_view.ex @@ -14,14 +14,15 @@ defmodule CodeCorpsWeb.ProjectView do :total_monthly_donated, :updated_at, :website ] - has_one :organization, serializer: CodeCorpsWeb.OrganizationView, include: true + has_one :organization, type: "organization", field: :organization_id has_one :stripe_connect_plan, serializer: CodeCorpsWeb.StripeConnectPlanView has_many :donation_goals, serializer: CodeCorpsWeb.DonationGoalView, identifiers: :always - has_many :project_categories, serializer: CodeCorpsWeb.ProjectCategoryView, include: true + has_many :project_categories, serializer: CodeCorpsWeb.ProjectCategoryView, identifiers: :always has_many :project_github_repos, serializer: CodeCorpsWeb.ProjectGithubRepoView, identifiers: :always - has_many :project_skills, serializer: CodeCorpsWeb.ProjectSkillView, include: true - has_many :project_users, serializer: CodeCorpsWeb.ProjectUserView, include: true + has_many :project_skills, serializer: CodeCorpsWeb.ProjectSkillView, identifiers: :always + has_many :project_users, serializer: CodeCorpsWeb.ProjectUserView, identifiers: :always + has_many :tasks, serializer: CodeCorpsWeb.TaskView, identifiers: :always has_many :task_lists, serializer: CodeCorpsWeb.TaskListView, identifiers: :always def can_activate_donations(project, _conn) do diff --git a/lib/code_corps_web/views/task_list_view.ex b/lib/code_corps_web/views/task_list_view.ex index b548eec92..63bb18cb6 100644 --- a/lib/code_corps_web/views/task_list_view.ex +++ b/lib/code_corps_web/views/task_list_view.ex @@ -7,5 +7,5 @@ defmodule CodeCorpsWeb.TaskListView do has_one :project, type: "project", field: :project_id - has_many :tasks, serializer: CodeCorpsWeb.TaskInListView, include: true + has_many :tasks, serializer: CodeCorpsWeb.TaskView, identifiers: :always end