Browse Source

chore: mix format

master
Inhji Y. 10 months ago
parent
commit
e5fa74f2b4
  1. 4
      apps/blog/lib/blog.ex
  2. 48
      apps/tomie_web/lib/tomie_web/controllers/blog_controller.ex

4
apps/blog/lib/blog.ex

@ -28,7 +28,7 @@ defmodule Blog do
def list_posts(limit \\ 10) do
Post
|> where(type: "post")
|> where(type: "post")
|> limit(^limit)
|> order_by([p], desc: p.inserted_at)
|> Db.Repo.all()
@ -52,7 +52,7 @@ defmodule Blog do
|> limit(^limit)
|> order_by([p], desc: p.inserted_at)
|> Db.Repo.all()
|> Db.Repo.preload(@preloads)
|> Db.Repo.preload(@preloads)
end
def delete_post(post) do

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

@ -2,46 +2,46 @@ defmodule TomieWeb.BlogController do
use TomieWeb, :controller
def index(conn, _params) do
posts = Blog.list_posts()
posts = Blog.list_posts()
render(conn, "index.html", posts: posts)
render(conn, "index.html", posts: posts)
end
def edit(conn, %{"id" => id}) do
post = Blog.get_post!(id)
changeset = Blog.Post.changeset(post)
post = Blog.get_post!(id)
changeset = Blog.Post.changeset(post)
render(conn, "edit.html", post: post, changeset: changeset)
render(conn, "edit.html", post: post, changeset: changeset)
end
def update(conn, %{"id" => id, "post" => post_params}) do
post = Blog.get_post!(id)
post = Blog.get_post!(id)
case Blog.update_post(post, post_params) do
{:ok, _post} ->
conn
|> redirect(to: Routes.blog_path(conn, :index))
case Blog.update_post(post, post_params) do
{:ok, _post} ->
conn
|> redirect(to: Routes.blog_path(conn, :index))
{:error, changeset} ->
render(conn, "edit.html", changeset: changeset)
end
{:error, changeset} ->
render(conn, "edit.html", changeset: changeset)
end
end
def new(conn, _params) do
changeset = Blog.Post.changeset(%Blog.Post{})
changeset = Blog.Post.changeset(%Blog.Post{})
render(conn, "new.html", changeset: changeset)
render(conn, "new.html", changeset: changeset)
end
def create(conn, %{"post" => post_params}) do
case Blog.create_post(post_params) do
{:ok, _post} ->
conn
|> redirect(to: Routes.blog_path(conn, :index))
{:error, changeset} ->
render(conn, "new.html", changeset: changeset)
end
case Blog.create_post(post_params) do
{:ok, _post} ->
conn
|> redirect(to: Routes.blog_path(conn, :index))
{:error, changeset} ->
render(conn, "new.html", changeset: changeset)
end
end
def delete(conn, %{"id" => id}) do
@ -52,4 +52,4 @@ defmodule TomieWeb.BlogController do
|> put_flash(:info, "Post deleted!")
|> redirect(to: Routes.blog_path(conn, :index))
end
end
end
Loading…
Cancel
Save