mirror of
https://github.com/astuto/astuto.git
synced 2025-12-15 11:17:49 +01:00
38 lines
839 B
Ruby
38 lines
839 B
Ruby
class PostsController < ApplicationController
|
|
# before_action :authenticate_user!
|
|
|
|
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(filter_params)
|
|
|
|
render json: posts
|
|
end
|
|
|
|
def create
|
|
post = Post.new(post_params)
|
|
post.user_id = current_user.id
|
|
|
|
if post.save
|
|
render json: { status: 'success' }
|
|
else
|
|
render json: { status: 'error', message: post.errors.full_messages }
|
|
end
|
|
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
|