Skip to content

Commit

Permalink
delete route for scene listings added
Browse files Browse the repository at this point in the history
  • Loading branch information
nikk15 committed Sep 14, 2023
1 parent 77e39ca commit 17e88ff
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions lib/ret_web/controllers/api/v1/scene_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,42 @@ defmodule RetWeb.Api.V1.SceneController do
create_or_update(conn, params)
end

# def delete(conn, %{"id" => scene_listing_sid}) do
# IO.inspect("DELETE")
# case scene_listing_sid |> Repo.get_by(scene_listing_sid) do
# %SceneListing{} = scene_listing ->
# Repo.delete(scene_listing)
# send_resp(conn, 200, "OK")

# nil ->
# render_error_json(conn, :not_found)
# end
# end

def delete(conn, %{"id" => scene_listing_sid}) do
account = Guardian.Plug.current_resource(conn)

case scene_listing_sid |> Scene.scene_or_scene_listing_by_sid() do
%SceneListing{} = scene_listing -> delete(conn, scene_listing, account)
_ -> conn |> send_resp(404, "not found")
end
end

def delete(conn, _scene_listing), do: conn |> send_resp(401, "You do not own this avatar")

def delete(conn, %SceneListing{account_id: scene_listing_account_id} = scene_listing, %Account{

Check failure on line 103 in lib/ret_web/controllers/api/v1/scene_controller.ex

View workflow job for this annotation

GitHub Actions / lint-and-test

** (CompileError) lib/ret_web/controllers/api/v1/scene_controller.ex:103: unknown key :account_id for struct Ret.SceneListing
account_id: account_id
})
# when not is_nil(scene_listing_account_id) and scene_listing_account_id == account_id
do
scene_listing
|> Repo.delete(scene_listing)
|> case do
{:ok, _} -> send_resp(conn, 200, "OK")
{:error, error} -> render_error_json(conn, error)
end
end

defp get_scene(scene_sid) do
case scene_sid |> Scene.scene_or_scene_listing_by_sid() do
nil -> nil
Expand Down

0 comments on commit 17e88ff

Please sign in to comment.