Skip to content

Commit

Permalink
fix: return 204 when deleting tenant
Browse files Browse the repository at this point in the history
  • Loading branch information
w3b6x9 committed Jun 2, 2022
1 parent e1b110d commit 317ac40
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 12 deletions.
4 changes: 1 addition & 3 deletions lib/realtime/api.ex
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,7 @@ defmodule Realtime.Api do

@spec delete_tenant_by_external_id(String.t()) :: true | false
def delete_tenant_by_external_id(id) do
Cachex.del(:tenants, id)
{num, _} = from(t in Tenant, where: t.external_id == ^id) |> Repo.delete_all()
num > 0
from(t in Tenant, where: t.external_id == ^id) |> Repo.delete_all()
end

@doc """
Expand Down
10 changes: 2 additions & 8 deletions lib/realtime_web/controllers/tenant_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,8 @@ defmodule RealtimeWeb.TenantController do
end

def delete(conn, %{"id" => id}) do
status =
if Api.delete_tenant_by_external_id(id) do
204
else
404
end

send_resp(conn, status, "")
Api.delete_tenant_by_external_id(id)
send_resp(conn, 204, "")
end

def swagger_definitions do
Expand Down
2 changes: 1 addition & 1 deletion test/realtime_web/controllers/tenant_controller_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ defmodule RealtimeWeb.TenantControllerTest do
test "tenant doesn't exist", %{conn: conn, tenant: tenant} do
with_mock JwtVerification, verify: fn _token, _secret -> {:ok, %{}} end do
conn = delete(conn, Routes.tenant_path(conn, :delete, "wrong_external_id"))
assert response(conn, 404)
assert response(conn, 204)
end
end
end
Expand Down

0 comments on commit 317ac40

Please sign in to comment.