From e6e344745b9d956773d875b4ab5e0d47947b3706 Mon Sep 17 00:00:00 2001 From: KKlochko Date: Tue, 1 Aug 2023 18:02:14 +0300 Subject: [PATCH] Add the API to update the Link model. --- CHANGELOG.org | 2 ++ .../controllers/api/v1/link_controller.ex | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/CHANGELOG.org b/CHANGELOG.org index e438dc5..bd4d557 100644 --- a/CHANGELOG.org +++ b/CHANGELOG.org @@ -32,4 +32,6 @@ 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. diff --git a/lib/link_shortener_web/controllers/api/v1/link_controller.ex b/lib/link_shortener_web/controllers/api/v1/link_controller.ex index c4bd5ad..971a568 100644 --- a/lib/link_shortener_web/controllers/api/v1/link_controller.ex +++ b/lib/link_shortener_web/controllers/api/v1/link_controller.ex @@ -24,6 +24,13 @@ defmodule LinkShortenerWeb.Api.V1.LinkController do link = Links.get_one(id) render(conn, "show.json", link: link) 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 def delete(conn, %{"id" => id}) do