Browse Source

feat: delete posts

master
Inhji Y. 10 months ago
parent
commit
ae3e114551
  1. 9
      apps/tomie_web/lib/tomie_web/controllers/blog_controller.ex
  2. 1
      apps/tomie_web/lib/tomie_web/router.ex
  3. 1
      apps/tomie_web/lib/tomie_web/templates/blog/index.html.eex

9
apps/tomie_web/lib/tomie_web/controllers/blog_controller.ex

@ -43,4 +43,13 @@ defmodule TomieWeb.BlogController do
render(conn, "new.html", changeset: changeset)
end
end
def delete(conn, %{"id" => id}) do
post = Blog.get_post!(id)
{:ok, _post} = Blog.delete_post(post)
conn
|> put_flash(:info, "Post deleted!")
|> redirect(to: Routes.blog_path(conn, :index))
end
end

1
apps/tomie_web/lib/tomie_web/router.ex

@ -72,6 +72,7 @@ defmodule TomieWeb.Router do
get "/posts/:id/edit", BlogController, :edit
post "/posts/:id/edit", BlogController, :update
put "/posts/:id/edit", BlogController, :update
delete "/posts/:id", BlogController, :delete
live "/bookmarks", BookmarkLive.Index
live "/bookmarks/new", BookmarkLive.New

1
apps/tomie_web/lib/tomie_web/templates/blog/index.html.eex

@ -23,6 +23,7 @@
<footer>
<%= link "Edit", to: Routes.blog_path(@conn, :edit, post.id), class: "button" %>
<%= link "Delete", to: Routes.blog_path(@conn, :delete, post.id), method: :delete, data: [confirm: "Are you sure?"], class: "button" %>
</footer>
</article>
<% end %>
Loading…
Cancel
Save