1
0
mirror of https://github.com/mgerb/classic-wow-forums synced 2026-01-11 09:32:51 +00:00

lots of things done: thread - reply - category - seeds

This commit is contained in:
2018-01-02 23:38:17 -06:00
parent 3a61151191
commit 115dacdd12
15 changed files with 291 additions and 27 deletions

32
lib/myapp/data/reply.ex Normal file
View File

@@ -0,0 +1,32 @@
defmodule MyApp.Data.Reply do
use Ecto.Schema
import Ecto.Query
import Ecto.Changeset
alias MyApp.Repo
alias MyApp.Data
@derive {Poison.Encoder, except: [:__meta__]}
schema "reply" do
field :user_id, :integer # references :user
field :thread_id, :integer # references :thread
field :content, :string
field :edited, :boolean, default: false
field :quote, :boolean, default: false
timestamps()
end
def changeset(reply, params \\ %{}) do
reply
|> cast(params, [:user_id, :thread_id, :content, :edited, :quote])
|> validate_required([:user_id, :thread_id, :content])
|> foreign_key_constraint(:user_id)
|> foreign_key_constraint(:thread_id)
end
def insert_reply(params) do
changeset(%Data.Reply{}, params)
|> Repo.insert
|> Data.Util.process_insert_or_update
end
end