Skip to content

Commit

Permalink
fix: sorting posts by most recent
Browse files Browse the repository at this point in the history
  • Loading branch information
SoraAsc committed Jan 6, 2025
1 parent 1e2238f commit 0cf43db
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/pescarte/blog/blog.ex
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ defmodule Pescarte.Blog do
|> apply_post_search_filter(filters)
|> apply_post_date_filter(filters)
|> apply_post_tag_filter(filters)
|> apply_order_by()
|> apply_pagination(filters)
|> Repo.replica().all()
end
Expand All @@ -47,6 +48,10 @@ defmodule Pescarte.Blog do

defp apply_post_tag_filter(query, _), do: query

defp apply_order_by(query) do
from p in query, order_by: [desc: p.published_at]
end

defp apply_pagination(query, %{page: page, page_size: page_size}) do
offset = (page - 1) * page_size
from p in query, limit: ^page_size, offset: ^offset
Expand Down

0 comments on commit 0cf43db

Please sign in to comment.