mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-27 21:47:59 +01:00
ae5bfe14e4
* Adding routes for /forums Adding routes for new /forums endpoints * New API Routes `/forum` `/forum/:forum_id` * Add New API Routes `/forums/:forum_id/topics/:topic_id/` `/forums/:forum_id/topics/:topic_id/:post_id` * Adds New API Routes `/forums/:forum_id/topics` `/forums/:forum_id/topics/:topic_id` * Forum JSON formatter * Updated Correctly filters out things that should not be shown. * Added topic JSON filter * Added correct pagination * Spacing and neatened * Cleaned up Consolidated queries and neatened up spacing. Fixed name * Removed unneeded aliases * Cleaned up Consolidated queries Fixed spacing Removed unneeded aliases * Cleaned up Spacing * Cleaned up spacing * Depluralized * Cleaned up Removed space * Removed extra spaces * Removed extra spaces * Removed extra spaces * Removed preloads * Cleaned up Grouped clauses * Consolodated further * Cleaned up preloads * Cleaned up Preloads consolidated clauses grouped clauses * Cleaned up removed `id` `locked` * Removed topic_id Not useful since the API client should already know it. * More consolodation of terms * Add total post count * Removed unneeded variable * Last cleanup, I swear.
28 lines
785 B
Elixir
28 lines
785 B
Elixir
defmodule PhilomenaWeb.PostJson do
|
|
alias PhilomenaWeb.UserAttributionView
|
|
|
|
def as_json(%{topic: %{hidden_from_users: true}} = post) do
|
|
%{
|
|
id: post.id,
|
|
user_id: nil,
|
|
author: nil,
|
|
body: nil
|
|
}
|
|
end
|
|
def as_json(%{hidden_from_users: true} = post) do
|
|
%{
|
|
id: post.id,
|
|
user_id: if(not post.anonymous, do: post.user_id),
|
|
author: if(post.anonymous or is_nil(post.user), do: UserAttributionView.anonymous_name(post), else: post.user.name),
|
|
body: nil
|
|
}
|
|
end
|
|
def as_json(post) do
|
|
%{
|
|
id: post.id,
|
|
user_id: if(not post.anonymous, do: post.user_id),
|
|
author: if(post.anonymous or is_nil(post.user), do: UserAttributionView.anonymous_name(post), else: post.user.name),
|
|
body: post.body
|
|
}
|
|
end
|
|
end
|