mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-28 05:57:58 +01:00
23 lines
637 B
Elixir
23 lines
637 B
Elixir
|
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}
|
||
|
rendered = Renderer.render_one(post)
|
||
|
|
||
|
render(conn, "create.html", layout: false, post: post, body: rendered)
|
||
|
end
|
||
|
|
||
|
defp preload_awards(nil), do: nil
|
||
|
defp preload_awards(user) do
|
||
|
Repo.preload(user, awards: :badge)
|
||
|
end
|
||
|
end
|