philomena/lib/philomena_web/controllers/post/preview_controller.ex

25 lines
645 B
Elixir
Raw Normal View History

defmodule PhilomenaWeb.Post.PreviewController do
use PhilomenaWeb, :controller
alias Philomena.Textile.Renderer
alias Philomena.Posts.Post
alias Philomena.Repo
def create(conn, params) do
user = preload_awards(conn.assigns.current_user)
body = to_string(params["body"])
anonymous = params["anonymous"] == true
post = %Post{user: user, body: body, anonymous: anonymous}
2019-12-01 18:11:00 +01:00
rendered = Renderer.render_one(post, conn)
render(conn, "create.html", layout: false, post: post, body: rendered)
end
defp preload_awards(nil), do: nil
2020-01-11 05:20:19 +01:00
defp preload_awards(user) do
Repo.preload(user, awards: :badge)
end
2020-01-11 05:20:19 +01:00
end