From ffb5609bab14252f671ddbaa548c2faa8d95bbc6 Mon Sep 17 00:00:00 2001 From: Josh Smith Date: Sat, 8 Oct 2016 16:39:30 -0700 Subject: [PATCH] Convert user skill controller except create --- web/controllers/user_skill_controller.ex | 27 ++++++------------------ web/models/user_skill.ex | 6 ------ 2 files changed, 7 insertions(+), 26 deletions(-) diff --git a/web/controllers/user_skill_controller.ex b/web/controllers/user_skill_controller.ex index 6f02d55c6..13314a0f5 100644 --- a/web/controllers/user_skill_controller.ex +++ b/web/controllers/user_skill_controller.ex @@ -1,5 +1,9 @@ defmodule CodeCorps.UserSkillController do use CodeCorps.Web, :controller + use JaResource + + import CodeCorps.FilterHelpers, only: [id_filter: 2] + alias CodeCorps.UserSkill @analytics Application.get_env(:code_corps, :analytics) @@ -7,15 +11,10 @@ defmodule CodeCorps.UserSkillController do plug :load_resource, model: UserSkill, only: [:show], preload: [:user, :skill] plug :load_and_authorize_changeset, model: UserSkill, only: [:create] plug :load_and_authorize_resource, model: UserSkill, only: [:delete] - plug :scrub_params, "data" when action in [:create] + plug JaResource, except: [:create] - def index(conn, params) do - user_skills = - UserSkill - |> UserSkill.index_filters(params) - |> Repo.all - - render(conn, "index.json-api", data: user_skills) + def filter(_conn, query, "id", id_list) do + query |> id_filter(id_list) end def create(conn, %{"data" => %{"type" => "user-skill"}}) do @@ -32,16 +31,4 @@ defmodule CodeCorps.UserSkillController do |> render(CodeCorps.ChangesetView, "error.json-api", changeset: changeset) end end - - def show(conn, %{"id" => _id}) do - render(conn, "show.json-api", data: conn.assigns.user_skill) - end - - def delete(conn, %{"id" => _id}) do - conn.assigns.user_skill |> Repo.delete! - - conn - |> @analytics.track(:removed, conn.assigns.user_skill) - |> send_resp(:no_content, "") - end end diff --git a/web/models/user_skill.ex b/web/models/user_skill.ex index 0a3c877f5..a486416b9 100644 --- a/web/models/user_skill.ex +++ b/web/models/user_skill.ex @@ -1,8 +1,6 @@ defmodule CodeCorps.UserSkill do use CodeCorps.Web, :model - import CodeCorps.ModelHelpers - schema "user_skills" do belongs_to :user, CodeCorps.User belongs_to :skill, CodeCorps.Skill @@ -21,8 +19,4 @@ defmodule CodeCorps.UserSkill do |> assoc_constraint(:skill) |> unique_constraint(:user_id, name: :index_projects_on_user_id_skill_id) end - - def index_filters(query, params) do - query |> id_filter(params) - end end