From 361287cb2a74945d30959ea3ea712cc7382d1ac0 Mon Sep 17 00:00:00 2001 From: Rudolf Manusadzhian Date: Wed, 1 May 2019 01:46:09 -0700 Subject: [PATCH] Avoid using the pipe operator just once. (see Style Guide https://github.com/christopheradams/elixir_style_guide#avoid-single-pipelines) overall code formatting more consistent --- lib/real_world/accounts/users.ex | 4 +--- .../controllers/article_controller.ex | 18 ++++++------------ .../controllers/comment_controller.ex | 7 +++---- .../controllers/profile_controller.ex | 6 ++---- .../controllers/session_controller.ex | 3 +-- .../controllers/user_controller.ex | 3 +-- 6 files changed, 14 insertions(+), 27 deletions(-) diff --git a/lib/real_world/accounts/users.ex b/lib/real_world/accounts/users.ex index ba8ba94..6c38361 100644 --- a/lib/real_world/accounts/users.ex +++ b/lib/real_world/accounts/users.ex @@ -23,9 +23,7 @@ defmodule RealWorld.Accounts.Users do end def unfollow(user, followee) do - relation = - UserFollower - |> Repo.get_by(user_id: user.id, followee_id: followee.id) + relation = Repo.get_by(UserFollower, user_id: user.id, followee_id: followee.id) case relation do nil -> diff --git a/lib/real_world_web/controllers/article_controller.ex b/lib/real_world_web/controllers/article_controller.ex index 153ca5e..58a5fef 100644 --- a/lib/real_world_web/controllers/article_controller.ex +++ b/lib/real_world_web/controllers/article_controller.ex @@ -19,7 +19,8 @@ defmodule RealWorldWeb.ArticleController do def index(conn, params, user) do articles = - Blog.list_articles(params) + params + |> Blog.list_articles() |> Repo.preload([:author, :favorites]) |> Blog.load_favorites(user) @@ -37,9 +38,7 @@ defmodule RealWorldWeb.ArticleController do def create(conn, %{"article" => params}, user) do with {:ok, %Article{} = article} <- Blog.create_article(create_params(params, user)) do - article = - article - |> Repo.preload([:author, :favorites]) + article = Repo.preload(article, [:author, :favorites]) conn |> put_status(:created) @@ -49,8 +48,7 @@ defmodule RealWorldWeb.ArticleController do end defp create_params(params, user) do - params - |> Map.merge(%{"user_id" => user.id}) + Map.merge(params, %{"user_id" => user.id}) end def show(conn, %{"id" => slug}, user) do @@ -76,9 +74,7 @@ defmodule RealWorldWeb.ArticleController do end def favorite(conn, %{"slug" => slug}, user) do - article = - slug - |> Blog.get_article_by_slug!() + article = Blog.get_article_by_slug!(slug) with {:ok, %Favorite{}} <- Blog.favorite(user, article) do article = @@ -91,9 +87,7 @@ defmodule RealWorldWeb.ArticleController do end def unfavorite(conn, %{"slug" => slug}, user) do - article = - slug - |> Blog.get_article_by_slug!() + article = Blog.get_article_by_slug!(slug) with {:ok, _} <- Blog.unfavorite(article, user) do article = diff --git a/lib/real_world_web/controllers/comment_controller.ex b/lib/real_world_web/controllers/comment_controller.ex index fef7177..369e71d 100644 --- a/lib/real_world_web/controllers/comment_controller.ex +++ b/lib/real_world_web/controllers/comment_controller.ex @@ -10,11 +10,10 @@ defmodule RealWorldWeb.CommentController do plug(Guardian.Plug.EnsureAuthenticated when action in [:create, :update, :delete]) def index(conn, %{"article_id" => slug}, _user) do - article = Blog.get_article_by_slug!(slug) - comments = Blog.list_comments(article) - comments = - comments + slug + |> Blog.get_article_by_slug!() + |> Blog.list_comments() |> RealWorld.Repo.preload(:author) render(conn, "index.json", comments: comments) diff --git a/lib/real_world_web/controllers/profile_controller.ex b/lib/real_world_web/controllers/profile_controller.ex index bdb0005..333123d 100644 --- a/lib/real_world_web/controllers/profile_controller.ex +++ b/lib/real_world_web/controllers/profile_controller.ex @@ -25,8 +25,7 @@ defmodule RealWorldWeb.ProfileController do def follow(conn, %{"username" => username}, current_user) do case Users.get_by_username(username) do followee = %User{} -> - current_user - |> Users.follow(followee) + Users.follow(current_user, followee) conn |> put_status(:ok) @@ -46,8 +45,7 @@ defmodule RealWorldWeb.ProfileController do def unfollow(conn, %{"username" => username}, current_user) do case Users.get_by_username(username) do followee = %User{} -> - current_user - |> Users.unfollow(followee) + Users.unfollow(current_user, followee) conn |> put_status(:ok) diff --git a/lib/real_world_web/controllers/session_controller.ex b/lib/real_world_web/controllers/session_controller.ex index e44cd8b..2b54033 100644 --- a/lib/real_world_web/controllers/session_controller.ex +++ b/lib/real_world_web/controllers/session_controller.ex @@ -8,8 +8,7 @@ defmodule RealWorldWeb.SessionController do def create(conn, params) do case Auth.find_user_and_check_password(params) do {:ok, user} -> - {:ok, jwt, _full_claims} = - user |> RealWorldWeb.Guardian.encode_and_sign(%{}, token_type: :token) + {:ok, jwt, _full_claims} = RealWorldWeb.Guardian.encode_and_sign(user, %{}, token_type: :token) conn |> put_status(:created) diff --git a/lib/real_world_web/controllers/user_controller.ex b/lib/real_world_web/controllers/user_controller.ex index adfd88c..b19984f 100644 --- a/lib/real_world_web/controllers/user_controller.ex +++ b/lib/real_world_web/controllers/user_controller.ex @@ -11,8 +11,7 @@ defmodule RealWorldWeb.UserController do def create(conn, %{"user" => user_params}, _) do case Auth.register(user_params) do {:ok, user} -> - {:ok, jwt, _full_claims} = - user |> RealWorldWeb.Guardian.encode_and_sign(%{}, token_type: :token) + {:ok, jwt, _full_claims} = RealWorldWeb.Guardian.encode_and_sign(user, %{}, token_type: :token) conn |> put_status(:created)