1
0
mirror of https://github.com/mgerb/classic-wow-forums synced 2026-01-12 01:52:49 +00:00

cache character end point - update reply count/thread reply id

This commit is contained in:
2018-01-09 23:24:09 -06:00
parent 2d6ff0875f
commit d3d3bef9a5
17 changed files with 226 additions and 22 deletions

View File

@@ -16,6 +16,7 @@ defmodule MyApp.Data.Thread do
field :sticky, :boolean, default: false
field :locked, :boolean, default: false
field :edited, :boolean, default: false
field :reply_count, :integer, default: 0
has_many :replies, Data.Reply
has_one :user, Data.User, foreign_key: :id, references: :user_id
has_one :last_reply, Data.User, foreign_key: :id, references: :last_reply_id
@@ -24,7 +25,7 @@ defmodule MyApp.Data.Thread do
defp insert_changeset(thread, params \\ %{}) do
thread
|> cast(params, [:title, :category_id, :content, :user_id])
|> cast(params, [:title, :category_id, :content, :user_id, :last_reply_id])
|> validate_required([:title, :category_id, :content, :user_id])
|> foreign_key_constraint(:category_id)
|> foreign_key_constraint(:user_id)
@@ -66,6 +67,9 @@ defmodule MyApp.Data.Thread do
:edited,
:content,
:category_id,
:title,
:view_count,
:reply_count,
user: [:id, :battletag],
last_reply: [:id, :battletag],
]),
@@ -85,6 +89,7 @@ defmodule MyApp.Data.Thread do
@spec insert(map) :: {:ok, map} | {:error, map}
def insert(params) do
params = Map.put(params, "last_reply_id", Map.get(params, "user_id"))
insert_changeset(%Data.Thread{}, params)
|> Repo.insert
|> remove_associations