Skip to content

Commit

Permalink
feat(post-by-username): complete implementation for post by username
Browse files Browse the repository at this point in the history
  • Loading branch information
akinsey committed Oct 15, 2024
1 parent a2cdf5f commit f3ab29d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
8 changes: 7 additions & 1 deletion lib/epochtalk_server_web/controllers/post.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ defmodule EpochtalkServerWeb.Controllers.Post do
alias EpochtalkServerWeb.Helpers.ACL
alias EpochtalkServerWeb.Helpers.Sanitize
alias EpochtalkServerWeb.Helpers.Parse
alias EpochtalkServer.Models.Profile
alias EpochtalkServer.Models.Post
alias EpochtalkServer.Models.Poll
alias EpochtalkServer.Models.Thread
Expand Down Expand Up @@ -384,12 +385,17 @@ defmodule EpochtalkServerWeb.Controllers.Post do
per_page: limit,
desc: desc
),
count <- Profile.post_count_by_username(username),
{:has_posts, true} <- {:has_posts, posts != []} do
render(conn, :by_username, %{
posts: posts,
user: user,
priority: priority,
view_deleted_posts: view_deleted_posts
view_deleted_posts: view_deleted_posts,
count: count,
limit: limit,
page: page,
desc: desc
})
else
{:has_posts, false} ->
Expand Down
12 changes: 10 additions & 2 deletions lib/epochtalk_server_web/json/post_json.ex
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,18 @@ defmodule EpochtalkServerWeb.Controllers.PostJSON do
@doc """
Renders all `Post` for a particular `User`.
"""
def by_username(%{posts: posts, user: user, priority: priority, view_deleted_posts: view_deleted_posts}) do
posts
def by_username(%{posts: posts, user: user, priority: priority, view_deleted_posts: view_deleted_posts, count: count, limit: limit, page: page, desc: desc}) do
posts = posts
|> Enum.map(&(Map.put(&1, :body_html, &1.body) |> Map.delete(:body)))
|> handle_deleted_posts(nil, user, priority, view_deleted_posts)

%{
posts: posts,
page: page,
desc: desc,
limit: limit,
count: count
}
end

## === Private Helper Functions ===
Expand Down

0 comments on commit f3ab29d

Please sign in to comment.