Skip to content

Commit

Permalink
Convert user skill controller except create
Browse files Browse the repository at this point in the history
  • Loading branch information
joshsmith authored and begedin committed Oct 12, 2016
1 parent d88a166 commit ffb5609
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 26 deletions.
27 changes: 7 additions & 20 deletions web/controllers/user_skill_controller.ex
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
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)

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
Expand All @@ -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
6 changes: 0 additions & 6 deletions web/models/user_skill.ex
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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

0 comments on commit ffb5609

Please sign in to comment.