Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e6e344745b | ||
|
|
62e855e1b6 | ||
|
|
8f6ec31366 |
@@ -28,4 +28,10 @@
|
|||||||
Move Links to the Links context.
|
Move Links to the Links context.
|
||||||
Refactor to split the Links to a Link model and a Links logic.
|
Refactor to split the Links to a Link model and a Links logic.
|
||||||
Update the controller and the view for updated Link model.
|
Update the controller and the view for updated Link model.
|
||||||
|
** 0.4.4 <2023-08-01 Tue>
|
||||||
|
Fix Links.update_one/2.
|
||||||
|
** 0.4.5 <2023-08-01 Tue>
|
||||||
|
Fix the route path in LinkController.create/2.
|
||||||
|
** 0.4.6 <2023-08-01 Tue>
|
||||||
|
Add the API to update the Link model.
|
||||||
|
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ defmodule LinkShortener.Links.Links do
|
|||||||
end
|
end
|
||||||
|
|
||||||
def update_one(%Link{} = link, changes) do
|
def update_one(%Link{} = link, changes) do
|
||||||
Link
|
link
|
||||||
|> Link.changeset(changes)
|
|> Link.changeset(changes)
|
||||||
|> Repo.update()
|
|> Repo.update()
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ defmodule LinkShortenerWeb.Api.V1.LinkController do
|
|||||||
with {:ok, %Link{} = link} <- Links.insert_one(link_params) do
|
with {:ok, %Link{} = link} <- Links.insert_one(link_params) do
|
||||||
conn
|
conn
|
||||||
|> put_status(:created)
|
|> put_status(:created)
|
||||||
|> put_resp_header("location", Routes.link_path(conn, :show, link))
|
|> put_resp_header("location", Routes.v1_link_path(conn, :show, link))
|
||||||
|> render("show.json", link: link)
|
|> render("show.json", link: link)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -24,6 +24,13 @@ defmodule LinkShortenerWeb.Api.V1.LinkController do
|
|||||||
link = Links.get_one(id)
|
link = Links.get_one(id)
|
||||||
render(conn, "show.json", link: link)
|
render(conn, "show.json", link: link)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def update(conn, %{"id" => id, "link" => link_params}) do
|
||||||
|
link = Links.get_one(id)
|
||||||
|
|
||||||
|
with {:ok, %Link{} = link} <- Links.update_one(link, link_params) do
|
||||||
|
render(conn, "show.json", link: link)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def delete(conn, %{"id" => id}) do
|
def delete(conn, %{"id" => id}) do
|
||||||
|
|||||||
Reference in New Issue
Block a user