Add filter by post status

This commit is contained in:
riggraz
2019-09-03 12:58:44 +02:00
parent 0618974543
commit 88096b2262
9 changed files with 320 additions and 93 deletions

View File

@@ -0,0 +1,7 @@
class PostStatusesController < ApplicationController
def index
post_statuses = PostStatus.order(order: :asc)
render json: post_statuses
end
end

View File

@@ -3,11 +3,12 @@ class PostsController < ApplicationController
def index_by_board_id
board_id = params[:board_id] || 1
posts = Post
.left_outer_joins(:post_status)
.select('posts.title, posts.description, post_statuses.name as post_status_name, post_statuses.color as post_status_color')
.where(board_id: board_id)
.where(filter_params)
render json: posts
end
@@ -24,8 +25,13 @@ class PostsController < ApplicationController
end
private
def filter_params
params.permit(:board_id, :post_status_id)
end
def post_params
params.require(:post).permit(:title, :description, :board_id)
end
end