Skip to content

Commit

Permalink
feat(api): dELETE [ur]/api/v1/aliases/:address can be used to delete …
Browse files Browse the repository at this point in the history
…Alias via the API

close Shroud-email#68
  • Loading branch information
xmok committed Jul 8, 2024
1 parent 07ff176 commit 6bc0e96
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
18 changes: 18 additions & 0 deletions lib/shroud_web/controllers/api/v1/email_alias_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,22 @@ defmodule ShroudWeb.Api.V1.EmailAliasController do
|> render("error.json", error: "Unable to create email alias")
end
end

def delete(conn, %{"address" => address}) do
alias =
EmailAlias
|> where([ea], is_nil(ea.deleted_at))
|> Repo.get_by(address: address)

if is_nil(alias) do
conn
|> put_status(422)
|> put_view(ShroudWeb.ErrorView)
|> render("error.json", error: "Alias not found")
else
Aliases.delete_email_alias(alias.id)
conn
|> send_resp(:no_content, "")
end
end
end
1 change: 1 addition & 0 deletions lib/shroud_web/router.ex
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ defmodule ShroudWeb.Router do
pipe_through([:api, :require_confirmed_api_user])

resources("/aliases", EmailAliasController, only: [:index, :create])
delete("/aliases/:address", EmailAliasController, :delete)
resources("/domains", DomainController, only: [:index])
end

Expand Down

0 comments on commit 6bc0e96

Please sign in to comment.