diff --git a/CHANGELOG.org b/CHANGELOG.org index 5bfddc0..d68dc8b 100644 --- a/CHANGELOG.org +++ b/CHANGELOG.org @@ -21,4 +21,6 @@ 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. diff --git a/lib/link_shortener_web/controllers/api/v1/links_controller.ex b/lib/link_shortener_web/controllers/api/v1/links_controller.ex index 2e27b3e..81e1aca 100644 --- a/lib/link_shortener_web/controllers/api/v1/links_controller.ex +++ b/lib/link_shortener_web/controllers/api/v1/links_controller.ex @@ -23,4 +23,12 @@ defmodule LinkShortenerWeb.Api.V1.LinksController do link = Links.get_one(id) render(conn, "show.json", links: link) 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