diff options
Diffstat (limited to 'lib/aggiedit/rooms')
-rw-r--r-- | lib/aggiedit/rooms/comment.ex | 20 | ||||
-rw-r--r-- | lib/aggiedit/rooms/post.ex | 6 | ||||
-rw-r--r-- | lib/aggiedit/rooms/vote.ex | 20 |
3 files changed, 45 insertions, 1 deletions
diff --git a/lib/aggiedit/rooms/comment.ex b/lib/aggiedit/rooms/comment.ex new file mode 100644 index 0000000..6747ba3 --- /dev/null +++ b/lib/aggiedit/rooms/comment.ex @@ -0,0 +1,20 @@ +defmodule Aggiedit.Post.Comment do + use Ecto.Schema + import Ecto.Changeset + + schema "post_comments" do + field :comment, :string + + belongs_to :user, Aggiedit.Accounts.User + belongs_to :post, Aggiedit.Rooms.Post + + timestamps() + end + + @doc false + def changeset(comment, attrs) do + comment + |> cast(attrs, [:comment]) + |> validate_required([:comment]) + end +end diff --git a/lib/aggiedit/rooms/post.ex b/lib/aggiedit/rooms/post.ex index ee9450d..e1aa59a 100644 --- a/lib/aggiedit/rooms/post.ex +++ b/lib/aggiedit/rooms/post.ex @@ -5,18 +5,22 @@ defmodule Aggiedit.Rooms.Post do schema "posts" do field :body, :string field :title, :string + field :score, :integer belongs_to :room, Aggiedit.Rooms.Room belongs_to :user, Aggiedit.Accounts.User belongs_to :upload, Aggiedit.Uploads.Upload + has_many :votes, Aggiedit.Post.Vote + has_many :comments, Aggiedit.Post.Comment + timestamps() end @doc false def changeset(post, attrs) do post - |> cast(attrs, [:title, :body]) + |> cast(attrs, [:title, :body, :score]) |> validate_required([:title, :body]) end diff --git a/lib/aggiedit/rooms/vote.ex b/lib/aggiedit/rooms/vote.ex new file mode 100644 index 0000000..f402e87 --- /dev/null +++ b/lib/aggiedit/rooms/vote.ex @@ -0,0 +1,20 @@ +defmodule Aggiedit.Post.Vote do + use Ecto.Schema + import Ecto.Changeset + + schema "post_votes" do + field :is_up, :boolean + + belongs_to :user, Aggiedit.Accounts.User + belongs_to :post, Aggiedit.Rooms.Post + + timestamps() + end + + @doc false + def changeset(vote, attrs) do + vote + |> cast(attrs, [:direction]) + |> validate_required([:direction]) + end +end |