more changes to notes
This commit is contained in:
		| @@ -5,15 +5,15 @@ defmodule Memex.Notes.Note do | ||||
|   use Ecto.Schema | ||||
|   import Ecto.Changeset | ||||
|   alias Ecto.{Changeset, UUID} | ||||
|   alias Memex.{Accounts.User, Notes.Note} | ||||
|   alias Memex.Accounts.User | ||||
|  | ||||
|   @primary_key {:id, :binary_id, autogenerate: true} | ||||
|   @foreign_key_type :binary_id | ||||
|   schema "notes" do | ||||
|     field :title, :string | ||||
|     field :content, :string | ||||
|     field :tags, {:array, :string} | ||||
|     field :tags_string, :string, virtual: true | ||||
|     field :title, :string | ||||
|     field :visibility, Ecto.Enum, values: [:public, :private, :unlisted] | ||||
|  | ||||
|     belongs_to :user, User | ||||
| @@ -21,21 +21,31 @@ defmodule Memex.Notes.Note do | ||||
|     timestamps() | ||||
|   end | ||||
|  | ||||
|   @type t :: %Note{} | ||||
|   @type t :: %__MODULE__{ | ||||
|           title: String.t(), | ||||
|           content: String.t(), | ||||
|           tags: [String.t()] | nil, | ||||
|           tags_string: String.t(), | ||||
|           visibility: :public | :private | :unlisted, | ||||
|           user: User.t() | Ecto.Association.NotLoaded.t(), | ||||
|           user_id: User.id(), | ||||
|           inserted_at: NaiveDateTime.t(), | ||||
|           updated_at: NaiveDateTime.t() | ||||
|         } | ||||
|   @type id :: UUID.t() | ||||
|   @type changeset :: Changeset.t(t()) | ||||
|  | ||||
|   @doc false | ||||
|   @spec create_changeset(attrs :: map(), User.t()) :: changeset() | ||||
|   def create_changeset(attrs, %User{id: user_id}) do | ||||
|     %Note{} | ||||
|     %__MODULE__{} | ||||
|     |> cast(attrs, [:title, :content, :tags, :visibility]) | ||||
|     |> change(user_id: user_id) | ||||
|     |> cast_tags_string(attrs) | ||||
|     |> validate_required([:title, :content, :user_id, :visibility]) | ||||
|   end | ||||
|  | ||||
|   @spec update_changeset(Note.t(), attrs :: map(), User.t()) :: changeset() | ||||
|   @spec update_changeset(t(), attrs :: map(), User.t()) :: changeset() | ||||
|   def update_changeset(%{user_id: user_id} = note, attrs, %User{id: user_id}) do | ||||
|     note | ||||
|     |> cast(attrs, [:title, :content, :tags, :visibility]) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user