 
   def join("boards:" <> board_id, _params, socket) do
     current_user = socket.assigns.current_user
-
-    cards_query = from c in Card, order_by: c.position
-    lists_query = from l in List, order_by: l.position, preload: [cards: ^cards_query]
-
-    board = Board.for_user(current_user.id)
-      |> Repo.get(board_id)
-      |> Repo.preload([:user, :invited_users, lists: lists_query])
+    board = get_current_board(board_id, socket)
 
     send(self, {:after_join, Monitor.user_joined(board_id, current_user)[board_id]})
 

    {:noreply, socket}
  end

  def terminate(_reason, socket) do
    board_id = to_string(socket.assigns.board.id)
    user_id = socket.assigns.current_user.id


    :ok
  end

  defp get_current_board(board_id, socket) do
    current_user = socket.assigns.current_user

    cards_query = from c in Card, order_by: c.position
    lists_query = from l in List, order_by: l.position, preload: [cards: ^cards_query]

    Board.for_user(current_user.id)
      |> Repo.get(board_id)
      |> Repo.preload([:user, :invited_users, lists: lists_query])
  end
end
