Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/textbin_web/controllers/apiv1/paste_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ defmodule TextbinWeb.ApiV1.PasteController do
conn
|> put_status(:created)
|> put_resp_header("location", ~p"/api/v1/pastes/#{paste.id}")
|> render(:show, paste: paste)
|> render(:create, paste: paste)

{:error, changeset} ->
render_changeset_errors(conn, changeset)
Expand Down
6 changes: 5 additions & 1 deletion lib/textbin_web/controllers/apiv1/paste_json.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@ defmodule TextbinWeb.ApiV1.PasteJSON do
%{data: for(paste <- pastes, do: data(paste))}
end

def show(%{paste: paste}) do
def create(%{paste: paste}) do
%{data: data(paste) |> Map.delete(:data)}
end

def show(%{paste: paste}) do
%{data: data(paste)}
end

defp data(%Paste{} = paste) do
%{
id: paste.id,
Expand Down
4 changes: 2 additions & 2 deletions test/textbin_web/controllers/apiv1/paste_controller_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ defmodule TextbinWeb.ApiV1.PasteControllerTest do

assert %{
"id" => ^id,
"data" => "some data",
"syntax_highlight" => "elixir",
"inserted_at" => inserted_at,
"updated_at" => updated_at
} = response_data = json_response(conn, 200)["data"]
} = json_response(conn, 200)["data"]

refute Map.has_key?(response_data, "data")
assert_millisecond_timestamp(inserted_at)
assert_millisecond_timestamp(updated_at)
end
Expand Down
Loading