How to improve function and remove extra from it's code

Pseudo-Code as there are missing parameters in those functions, but it should convey the point. You could pass just the function name or the module and the function.

def test_1(), do: test(:name)
def test_2(), do: test(:other_name)

defp test(function_name) do
  with {:ok, %{acl: "admin", info: _info}} <- TrangellApiGateway.User.Login.user_acl_check(allreq),
            {:ok, ms} <- http_error_handeller(conn, apply(Post, function_name, [allreq]), "created")  do
            conn
            |> put_status(201)
            |> json(%{message: ms})  
      else
            _ ->
               conn
               |> put_status(400)
               |> json(%{error: "Your request is invalid."}) 
      end
end
1 Like