Compare commits
3
Commits
0.4.1
..
fb4f0025d1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fb4f0025d1 | ||
|
|
6799e5b00b | ||
|
|
b2fd493d07 |
@@ -21,4 +21,9 @@
|
|||||||
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>
|
** 0.4.1 <2023-07-29 Sat>
|
||||||
Add the API to create the Links model.
|
Add the API to create the Links model.
|
||||||
|
** 0.4.2 <2023-07-30 Sun>
|
||||||
|
Add the API to delete the Links model.
|
||||||
|
** 0.4.3 <2023-07-31 Mon>
|
||||||
|
Rename the controller and the view names to "Link".
|
||||||
|
Move Links to the Links context.
|
||||||
|
|
||||||
|
|||||||
+9
-1
@@ -1,4 +1,4 @@
|
|||||||
defmodule LinkShortenerWeb.Api.V1.LinksController do
|
defmodule LinkShortenerWeb.Api.V1.LinkController do
|
||||||
use LinkShortenerWeb, :controller
|
use LinkShortenerWeb, :controller
|
||||||
|
|
||||||
alias LinkShortener.Links
|
alias LinkShortener.Links
|
||||||
@@ -23,4 +23,12 @@ defmodule LinkShortenerWeb.Api.V1.LinksController 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
|
resources "/links", LinkController
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
+4
-4
@@ -1,13 +1,13 @@
|
|||||||
defmodule LinkShortenerWeb.Api.V1.LinksView do
|
defmodule LinkShortenerWeb.Api.V1.LinkView do
|
||||||
use LinkShortenerWeb, :view
|
use LinkShortenerWeb, :view
|
||||||
alias LinkShortenerWeb.Api.V1.LinksView
|
alias LinkShortenerWeb.Api.V1.LinkView
|
||||||
|
|
||||||
def render("index.json", %{links: links}) do
|
def render("index.json", %{links: links}) do
|
||||||
%{data: render_many(links, LinksView, "link.json")}
|
%{data: render_many(links, LinkView, "link.json")}
|
||||||
end
|
end
|
||||||
|
|
||||||
def render("show.json", %{links: link}) do
|
def render("show.json", %{links: link}) do
|
||||||
%{data: render_one(link, LinksView, "link.json")}
|
%{data: render_one(link, LinkView, "link.json")}
|
||||||
end
|
end
|
||||||
|
|
||||||
def render("link.json", %{links: link}) do
|
def render("link.json", %{links: link}) do
|
||||||
Reference in New Issue
Block a user