Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b2fd493d07 | ||
|
|
4e43da527f |
@@ -19,4 +19,8 @@
|
|||||||
Added the simple dev configuration.
|
Added the simple dev configuration.
|
||||||
** 0.4.0 <2023-07-28 Fri>
|
** 0.4.0 <2023-07-28 Fri>
|
||||||
Added the API to show the Links model or models.
|
Added the API to show the Links model or models.
|
||||||
|
** 0.4.1 <2023-07-29 Sat>
|
||||||
|
Add the API to create the Links model.
|
||||||
|
** 0.4.2 <2023-07-30 Sun>
|
||||||
|
Add the API to delete the Links model.
|
||||||
|
|
||||||
|
|||||||
@@ -10,8 +10,25 @@ defmodule LinkShortenerWeb.Api.V1.LinksController do
|
|||||||
render(conn, "index.json", links: links)
|
render(conn, "index.json", links: links)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def create(conn, %{"link" => link_params}) do
|
||||||
|
with {:ok, %Links{} = link} <- Links.insert_one(link_params) do
|
||||||
|
conn
|
||||||
|
|> put_status(:created)
|
||||||
|
|> put_resp_header("location", Routes.links_path(conn, :show, link))
|
||||||
|
|> render("show.json", links: link)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def show(conn, %{"id" => id}) do
|
def show(conn, %{"id" => id}) do
|
||||||
link = Links.get_one(id)
|
link = Links.get_one(id)
|
||||||
render(conn, "show.json", links: link)
|
render(conn, "show.json", links: link)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def delete(conn, %{"id" => id}) do
|
||||||
|
link = Links.get_one(id)
|
||||||
|
|
||||||
|
with {:ok, %Link{}} <- Links.delete_one(link) do
|
||||||
|
send_resp(conn, :no_content, "")
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ defmodule LinkShortenerWeb.Router do
|
|||||||
pipe_through :api
|
pipe_through :api
|
||||||
|
|
||||||
scope "/v1", Api.V1, as: :v1 do
|
scope "/v1", Api.V1, as: :v1 do
|
||||||
resources "/links", LinksController, except: [:new, :edit]
|
resources "/links", LinksController
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user