2019-11-28 03:06:41 +01:00
|
|
|
defmodule PhilomenaWeb.Post.PreviewController do
|
|
|
|
use PhilomenaWeb, :controller
|
|
|
|
|
2021-09-12 21:03:59 +02:00
|
|
|
alias PhilomenaWeb.TextRenderer
|
2019-11-28 03:06:41 +01:00
|
|
|
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
|
|
|
|
|
2021-09-12 21:03:59 +02:00
|
|
|
post = %Post{user: user, body_md: body, anonymous: anonymous}
|
|
|
|
rendered = TextRenderer.render_one(post, conn)
|
2019-11-28 03:06:41 +01:00
|
|
|
|
|
|
|
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
|
|
|
|
2019-11-28 03:06:41 +01:00
|
|
|
defp preload_awards(user) do
|
|
|
|
Repo.preload(user, awards: :badge)
|
|
|
|
end
|
2020-01-11 05:20:19 +01:00
|
|
|
end
|