2019-08-22 17:09:13 +02:00
|
|
|
class BoardsController < ApplicationController
|
2022-05-08 16:36:35 +02:00
|
|
|
include ApplicationHelper
|
|
|
|
|
|
|
|
|
|
before_action :authenticate_admin, only: [:create, :update, :update_order, :destroy]
|
|
|
|
|
|
|
|
|
|
def index
|
|
|
|
|
boards = Board.order(order: :asc)
|
|
|
|
|
|
|
|
|
|
render json: boards
|
|
|
|
|
end
|
|
|
|
|
|
2019-08-22 17:09:13 +02:00
|
|
|
def show
|
|
|
|
|
@board = Board.find(params[:id])
|
|
|
|
|
end
|
2022-05-08 16:36:35 +02:00
|
|
|
|
|
|
|
|
def create
|
|
|
|
|
board = Board.new(board_params)
|
|
|
|
|
|
|
|
|
|
if board.save
|
|
|
|
|
render json: board, status: :created
|
|
|
|
|
else
|
|
|
|
|
render json: {
|
2022-06-05 11:40:43 +02:00
|
|
|
error: board.errors.full_messages
|
2022-05-08 16:36:35 +02:00
|
|
|
}, status: :unprocessable_entity
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def update
|
|
|
|
|
board = Board.find(params[:id])
|
|
|
|
|
board.assign_attributes(board_params)
|
|
|
|
|
|
|
|
|
|
if board.save
|
|
|
|
|
render json: board, status: :ok
|
|
|
|
|
else
|
|
|
|
|
print board.errors.full_messages
|
|
|
|
|
|
|
|
|
|
render json: {
|
2022-06-05 11:40:43 +02:00
|
|
|
error: board.errors.full_messages
|
2022-05-08 16:36:35 +02:00
|
|
|
}, status: :unprocessable_entity
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
|
board = Board.find(params[:id])
|
|
|
|
|
|
|
|
|
|
if board.destroy
|
|
|
|
|
render json: {
|
|
|
|
|
id: params[:id]
|
|
|
|
|
}, status: :accepted
|
|
|
|
|
else
|
|
|
|
|
render json: {
|
2022-06-05 11:40:43 +02:00
|
|
|
error: board.errors.full_messages
|
2022-05-08 16:36:35 +02:00
|
|
|
}, status: :unprocessable_entity
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def update_order
|
|
|
|
|
workflow_output = ReorderWorkflow.new(
|
|
|
|
|
entity_classname: Board,
|
|
|
|
|
column_name: 'order',
|
|
|
|
|
entity_id: params[:board][:id],
|
|
|
|
|
src_index: params[:board][:src_index],
|
|
|
|
|
dst_index: params[:board][:dst_index]
|
|
|
|
|
).run
|
|
|
|
|
|
|
|
|
|
if workflow_output
|
|
|
|
|
render json: workflow_output
|
|
|
|
|
else
|
|
|
|
|
render json: {
|
2022-06-05 11:40:43 +02:00
|
|
|
error: t("backend.errors.board.update_order")
|
2022-05-08 16:36:35 +02:00
|
|
|
}, status: :unprocessable_entity
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
private
|
|
|
|
|
def board_params
|
|
|
|
|
params
|
|
|
|
|
.require(:board)
|
|
|
|
|
.permit(:name, :description)
|
|
|
|
|
end
|
2019-08-22 17:09:13 +02:00
|
|
|
end
|