Class: Unsakini::BoardsController
- Inherits:
-
BaseController
- Object
- ActionController::API
- BaseController
- Unsakini::BoardsController
- Includes:
- ActionController::Serialization, BoardOwnerControllerConcern, LoggedInControllerConcern, SerializerControllerConcern
- Defined in:
- app/controllers/unsakini/boards_controller.rb
Instance Method Summary collapse
-
#create ⇒ Object
Creates board belonging to current user.
-
#destroy ⇒ Object
Deletes a board resource.
-
#index ⇒ Object
Returns boards belonging to current user.
-
#show ⇒ Object
Render a single board.
-
#update ⇒ Object
Updates a single board.
Methods included from BoardOwnerControllerConcern
#ensure_board, #ensure_board_owner, #has_board_access
Instance Method Details
#create ⇒ Object
Creates board belonging to current user.
‘POST /api/boards`
31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'app/controllers/unsakini/boards_controller.rb', line 31 def create @user_board = UserBoard.new( name: params[:board][:name], user_id: @user.id, encrypted_password: params[:encrypted_password], is_admin: true ) if @user_board.save render json: @user_board, status: :created else render json: @user_board.errors., status: 422 end end |
#destroy ⇒ Object
Deletes a board resource.
‘DELETE /api/boards/:id`
69 70 71 72 |
# File 'app/controllers/unsakini/boards_controller.rb', line 69 def destroy @board.destroy render json: {}, status: :ok end |
#index ⇒ Object
Returns boards belonging to current user
‘GET /api/boards`
17 18 19 20 21 22 23 24 25 |
# File 'app/controllers/unsakini/boards_controller.rb', line 17 def index admin = true shared = false admin = params[:is_admin] == 'true' if params[:admin] shared = params[:shared] == 'true' if params[:shared] result = @user.user_boards.shared(shared) result = result.admin if admin paginate json: result, per_page: 10 end |
#show ⇒ Object
Render a single board.
‘GET /api/boards/:id`
50 51 52 |
# File 'app/controllers/unsakini/boards_controller.rb', line 50 def show render json: @user_board end |
#update ⇒ Object
Updates a single board.
‘PUT /api/boards/:id`
57 58 59 60 61 62 63 64 |
# File 'app/controllers/unsakini/boards_controller.rb', line 57 def update if @user_board.update(name: params[:board][:name], encrypted_password: params[:encrypted_password]) render json: @user_board else errors = @board.errors..concat @user_board.errors. render json: errors, status: 422 end end |