Do not require `description` in `update` action
This commit is contained in:
parent
0f885b4b86
commit
bb03dfdb03
|
@ -53,10 +53,7 @@ def create2(%{assigns: %{user: user}, body_params: %{file: file} = data} = conn,
|
||||||
def create2(_conn, _data), do: {:error, :bad_request}
|
def create2(_conn, _data), do: {:error, :bad_request}
|
||||||
|
|
||||||
@doc "PUT /api/v1/media/:id"
|
@doc "PUT /api/v1/media/:id"
|
||||||
def update(%{assigns: %{user: user}, body_params: %{description: description}} = conn, %{
|
def update(%{assigns: %{user: user}, body_params: %{description: description}} = conn, %{id: id}) do
|
||||||
id: id
|
|
||||||
})
|
|
||||||
when is_binary(description) do
|
|
||||||
with %Object{} = object <- Object.get_by_id(id),
|
with %Object{} = object <- Object.get_by_id(id),
|
||||||
true <- Object.authorize_mutation(object, user),
|
true <- Object.authorize_mutation(object, user),
|
||||||
{:ok, %Object{data: data}} <- Object.update_data(object, %{"name" => description}) do
|
{:ok, %Object{data: data}} <- Object.update_data(object, %{"name" => description}) do
|
||||||
|
@ -66,7 +63,7 @@ def update(%{assigns: %{user: user}, body_params: %{description: description}} =
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def update(_conn, _data), do: {:error, :bad_request}
|
def update(conn, data), do: show(conn, data)
|
||||||
|
|
||||||
@doc "GET /api/v1/media/:id"
|
@doc "GET /api/v1/media/:id"
|
||||||
def show(conn, %{id: id}) do
|
def show(conn, %{id: id}) do
|
||||||
|
|
|
@ -94,16 +94,6 @@ test "/api/v1/media/:id good request", %{conn: conn, object: object} do
|
||||||
assert media["description"] == "test-media"
|
assert media["description"] == "test-media"
|
||||||
assert refresh_record(object).data["name"] == "test-media"
|
assert refresh_record(object).data["name"] == "test-media"
|
||||||
end
|
end
|
||||||
|
|
||||||
test "/api/v1/media/:id bad request", %{conn: conn, object: object} do
|
|
||||||
media =
|
|
||||||
conn
|
|
||||||
|> put_req_header("content-type", "multipart/form-data")
|
|
||||||
|> put("/api/v1/media/#{object.id}", %{})
|
|
||||||
|> json_response_and_validate_schema(400)
|
|
||||||
|
|
||||||
assert media == %{"error" => "bad_request"}
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "Get media by id" do
|
describe "Get media by id" do
|
||||||
|
|
Loading…
Reference in New Issue