From d818c7033a1f3f3ace8095fb962b33529c90ba5c Mon Sep 17 00:00:00 2001 From: SphericalKat Date: Thu, 12 Aug 2021 04:29:58 +0530 Subject: [PATCH] fix(models): prevent IDs being empty while inserting Signed-off-by: SphericalKat --- lib/ketbin/pastes/paste.ex | 4 +++- lib/ketbin_web/controllers/paste_controller.ex | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/ketbin/pastes/paste.ex b/lib/ketbin/pastes/paste.ex index 8c6cd5f..6b73696 100644 --- a/lib/ketbin/pastes/paste.ex +++ b/lib/ketbin/pastes/paste.ex @@ -2,6 +2,8 @@ defmodule Ketbin.Pastes.Paste do use Ecto.Schema import Ecto.Changeset + @primary_key {:id, :string, autogenerate: false} + @derive {Phoenix.Param, key: :id} schema "pastes" do field :content, :string field :is_url, :boolean, default: false @@ -11,7 +13,7 @@ defmodule Ketbin.Pastes.Paste do @doc false def changeset(paste, attrs) do paste - |> cast(attrs, [:is_url, :content]) + |> cast(attrs, [:is_url, :content, :id]) |> validate_required([:is_url, :content]) end end diff --git a/lib/ketbin_web/controllers/paste_controller.ex b/lib/ketbin_web/controllers/paste_controller.ex index 4e6ec80..3b02224 100644 --- a/lib/ketbin_web/controllers/paste_controller.ex +++ b/lib/ketbin_web/controllers/paste_controller.ex @@ -15,6 +15,7 @@ defmodule KetbinWeb.PasteController do end def create(conn, %{"paste" => paste_params}) do + # paste_params = Map.put(paste_params, "id", s) case Pastes.create_paste(paste_params) do {:ok, paste} -> conn