mirror of
https://github.com/astuto/astuto.git
synced 2025-12-16 03:37:56 +01:00
Improve post list filter by status (#267)
This commit is contained in:
committed by
GitHub
parent
30b7b0f5f4
commit
a7d67652bf
@@ -16,10 +16,13 @@ class PostsController < ApplicationController
|
||||
.left_outer_joins(:likes)
|
||||
.left_outer_joins(:comments)
|
||||
.group('posts.id')
|
||||
.where(filter_params)
|
||||
.where(board_id: params[:board_id] || Board.first.id)
|
||||
.search_by_name_or_description(params[:search])
|
||||
.order('hotness DESC')
|
||||
.page(params[:page])
|
||||
|
||||
# apply post status filter if present
|
||||
posts = posts.where(post_status_id: params[:post_status_ids].map { |id| id == "0" ? nil : id }) if params[:post_status_ids].present?
|
||||
|
||||
render json: posts
|
||||
end
|
||||
@@ -107,15 +110,6 @@ class PostsController < ApplicationController
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def filter_params
|
||||
defaults = Board.first ? { board_id: Board.first.id } : {}
|
||||
|
||||
params
|
||||
.permit(:board_id, :post_status_id, :page, :search)
|
||||
.with_defaults(defaults)
|
||||
.except(:page, :search)
|
||||
end
|
||||
|
||||
def post_create_params
|
||||
params
|
||||
|
||||
Reference in New Issue
Block a user