mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-24 12:37:58 +01:00
27 lines
894 B
Elixir
27 lines
894 B
Elixir
|
defmodule PhilomenaWeb.Topic.Post.DeleteController do
|
||
|
use PhilomenaWeb, :controller
|
||
|
|
||
|
alias Philomena.Posts.Post
|
||
|
alias Philomena.Posts
|
||
|
|
||
|
plug PhilomenaWeb.CanaryMapPlug, create: :hide, delete: :hide
|
||
|
plug :load_and_authorize_resource, model: Post, id_name: "post_id", persisted: true, preload: [:topic]
|
||
|
|
||
|
def delete(conn, _params) do
|
||
|
post = conn.assigns.post
|
||
|
|
||
|
case Posts.destroy_post(post) do
|
||
|
{:ok, post} ->
|
||
|
Posts.reindex_post(post)
|
||
|
|
||
|
conn
|
||
|
|> put_flash(:info, "Post successfully destroyed!")
|
||
|
|> redirect(to: Routes.forum_topic_path(conn, :show, post.topic.forum_id, post.topic_id) <> "#post_#{post.id}")
|
||
|
{:error, _changeset} ->
|
||
|
conn
|
||
|
|> put_flash(:error, "Unable to destroy post!")
|
||
|
|> redirect(to: Routes.forum_topic_path(conn, :show, post.topic.forum_id, post.topic_id) <> "#post_#{post.id}")
|
||
|
end
|
||
|
end
|
||
|
end
|