Fakultas Ilmu Komputer UI

Commit 2888589f authored by Muhammad Rafif Elfazri's avatar Muhammad Rafif Elfazri
Browse files

Change use get with get_by_name

parent 183056ed
......@@ -3,6 +3,7 @@ defmodule DiskuyWeb.TopicController do
alias Diskuy.Forum
alias Diskuy.Forum.Topic
alias Diskuy.Utility.Utility
action_fallback DiskuyWeb.FallbackController
......@@ -21,12 +22,15 @@ defmodule DiskuyWeb.TopicController do
end
def show(conn, %{"id" => id}) do
topic = Forum.get_topic!(id)
new_id = Utility.capitalize_string(id)
topic = Forum.get_topic_by_name!(new_id)
render(conn, "show.json", topic: topic)
end
def update(conn, %{"id" => id, "topic" => topic_params}) do
topic = Forum.get_topic!(id)
new_id = Utility.capitalize_string(id)
topic = Forum.get_topic_by_name!(new_id)
with {:ok, %Topic{} = topic} <- Forum.update_topic(topic, topic_params) do
render(conn, "show.json", topic: topic)
......@@ -34,7 +38,8 @@ defmodule DiskuyWeb.TopicController do
end
def delete(conn, %{"id" => id}) do
topic = Forum.get_topic!(id)
new_id = Utility.capitalize_string(id)
topic = Forum.get_topic_by_name!(new_id)
with {:ok, %Topic{}} <- Forum.delete_topic(topic) do
send_resp(conn, :no_content, "")
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment