···33 Schema containing information about a Comet comment.
44 """
55 use Comet.Schema
66+ import Ecto.Changeset
6778 schema "comments" do
89 field :rkey, :string
···1819 has_many :replies, __MODULE__, foreign_key: :reply_id
19202021 timestamps(inserted_at: :indexed_at, updated_at: false)
2222+ end
2323+2424+ def new(params \\ %{}), do: changeset(%__MODULE__{}, params)
2525+2626+ def changeset(struct, params \\ %{}) do
2727+ struct
2828+ |> cast(params, [:rkey, :did, :text, :facets, :subject_id, :subject_type, :langs, :created_at])
2929+ |> validate_required([:rkey, :text])
2130 end
2231end
+8
apps/backend/lib/comet/repo/embed/facet.ex
···11defmodule Comet.Repo.Embed.Facet do
22 use Comet.Schema
33+ import Ecto.Changeset
3445 @primary_key false
56 embedded_schema do
···10111112 # Sadly Ecto doesn't support union types/embeds so this has to be generic, without doing weirdness in the database at least
1213 field :features, {:array, :map}
1414+ end
1515+1616+ def changeset(struct, params \\ %{}) do
1717+ struct
1818+ |> cast(params, [:features])
1919+ |> cast_embed(:index, required: true)
2020+ |> validate_required([:features])
1321 end
1422end
+7
apps/backend/lib/comet/repo/embed/link.ex
···11defmodule Comet.Repo.Embed.Link do
22 use Comet.Schema
33+ import Ecto.Changeset
3445 @primary_key false
56 embedded_schema do
67 field :type, :string
78 field :value, :string
99+ end
1010+1111+ def changeset(struct, params \\ %{}) do
1212+ struct
1313+ |> cast(params, [:type, :value])
1414+ |> validate_required([:type, :value])
815 end
916end
+9-1
apps/backend/lib/comet/repo/identity.ex
···33 Schema containing information about an ATProtocol identity.
44 """
55 use Ecto.Schema
66+ import Ecto.Changeset
6778 @primary_key {:did, :string, autogenerate: false}
89 @foreign_key_type :string
···1011 schema "identity" do
1112 field :handle, :string
1213 field :active, :boolean
1313- # TODO: see if it'd be possible to set this to an enum, if ecto allows open enums
1414 field :status, :string
15151616 timestamps(inserted_at: :indexed_at, updated_at: false)
1717+ end
1818+1919+ def new(params \\ %{}), do: changeset(%__MODULE__{}, params)
2020+2121+ def changeset(struct, params \\ %{}) do
2222+ struct
2323+ |> cast(params, [:did, :handle, :active, :status])
2424+ |> validate_required([:did, :active])
1725 end
1826end
+9
apps/backend/lib/comet/repo/like.ex
···33 Schema containing information about a Comet like.
44 """
55 use Comet.Schema
66+ import Ecto.Changeset
6778 schema "likes" do
89 field :rkey, :string
···1314 belongs_to :identity, Repo.Identity, foreign_key: :did, references: :did
14151516 timestamps(inserted_at: :indexed_at, updated_at: false)
1717+ end
1818+1919+ def new(params \\ %{}), do: changeset(%__MODULE__{}, params)
2020+2121+ def changeset(struct, params \\ %{}) do
2222+ struct
2323+ |> cast(params, [:rkey, :did, :subject_id, :subject_type, :created_at])
2424+ |> validate_required([:rkey, :did, :subject_id, :subject_type, :created_at])
1625 end
1726end
+13-1
apps/backend/lib/comet/repo/playlist.ex
···11defmodule Comet.Repo.Playlist do
22 @moduledoc """
33- Schema containing information about a Comet playlist.
33+ Sch ema containing information about a Comet playlist.
44 """
55 use Comet.Schema
66+ import Ecto.Changeset
6778 schema "playlists" do
89 field :rkey, :string
910 field :title, :string
1011 field :image, :string
1112 field :description, :string
1313+ # TODO: see how this looks with/without primary id
1214 embeds_one :description_facets, Repo.Embed.Facet, on_replace: :update
1315 field :type, :string
1416 field :tags, {:array, :string}
···1921 has_many :tracks, Repo.Playlist
20222123 timestamps(inserted_at: :indexed_at, updated_at: false)
2424+ end
2525+2626+ def new(params \\ %{}), do: changeset(%__MODULE__{}, params)
2727+2828+ def changeset(struct, params \\ %{}) do
2929+ struct
3030+ |> cast(params, [:rkey, :did, :title, :image, :description, :type, :tags, :created_at])
3131+ |> cast_embed(:description_facets)
3232+ |> cast_embed(:link)
3333+ |> validate_required([:rkey, :did, :title, :type, :created_at])
2234 end
2335end
+9
apps/backend/lib/comet/repo/playlist_track.ex
···33 Schema containing information about a track in a Comet playlist.
44 """
55 use Comet.Schema
66+ import Ecto.Changeset
6778 schema "playlist_tracks" do
89 field :rkey, :string
···1415 belongs_to :playlist, Repo.Playlist
15161617 timestamps(inserted_at: :indexed_at, updated_at: false)
1818+ end
1919+2020+ def new(params \\ %{}), do: changeset(%__MODULE__{}, params)
2121+2222+ def changeset(struct, params \\ %{}) do
2323+ struct
2424+ |> cast(params, [:rkey, :did, :position, :created_at, :track_id, :playlist_id])
2525+ |> validate_required([:rkey, :did, :position, :created_at, :track_id, :playlist_id])
1726 end
1827end
+20
apps/backend/lib/comet/repo/profile.ex
···33 Schema containing information about a Comet profile.
44 """
55 use Comet.Schema
66+ import Ecto.Changeset
6788+ # TODO: should probably keep track of CID so as to not do unnecessary writes
79 schema "profiles" do
810 field :rkey, :string, default: "self"
911 field :display_name, :string
···1719 belongs_to :identity, Repo.Identity, foreign_key: :did, references: :did
18201921 timestamps(inserted_at: :indexed_at, updated_at: false)
2222+ end
2323+2424+ def new(params \\ %{}), do: changeset(%__MODULE__{}, params)
2525+2626+ def changeset(struct, params \\ %{}) do
2727+ struct
2828+ |> cast(params, [
2929+ :rkey,
3030+ :did,
3131+ :display_name,
3232+ :description,
3333+ :avatar,
3434+ :banner,
3535+ :featured_items,
3636+ :created_at
3737+ ])
3838+ |> cast_embed(:description_facets)
3939+ |> validate_required([:rkey, :did])
2040 end
2141end
+9
apps/backend/lib/comet/repo/repost.ex
···33 Schema containing information about a Comet repost.
44 """
55 use Comet.Schema
66+ import Ecto.Changeset
6778 schema "reposts" do
89 field :rkey, :string
···1314 belongs_to :identity, Repo.Identity, foreign_key: :did, references: :did
14151516 timestamps(inserted_at: :indexed_at, updated_at: false)
1717+ end
1818+1919+ def new(params \\ %{}), do: changeset(%__MODULE__{}, params)
2020+2121+ def changeset(struct, params \\ %{}) do
2222+ struct
2323+ |> cast(params, [:rkey, :did, :subject_id, :subject_type, :created_at])
2424+ |> validate_required([:rkey, :did, :subject_id, :subject_type, :created_at])
1625 end
1726end