Class: Api::BoardsController
- Inherits:
-
ApplicationController
- Object
- ActionController::API
- ApplicationController
- Api::BoardsController
- Defined in:
- app/controllers/api/boards_controller.rb
Constant Summary collapse
- ALLOWED_PARENT_CLASSES =
%w[peer_review application program space]
Instance Method Summary collapse
-
#add_user ⇒ Object
POST /boards/1/users/34.
-
#create ⇒ Object
POST /boards.
-
#destroy ⇒ Object
DELETE /boards/1.
-
#index ⇒ Object
GET /boards.
-
#remove_user ⇒ Object
DELETE /boards/1/users/34.
-
#show ⇒ Object
GET /boards/1.
-
#update ⇒ Object
PATCH/PUT /boards/1.
Methods included from Response
Instance Method Details
#add_user ⇒ Object
POST /boards/1/users/34
58 59 60 61 62 63 64 65 66 |
# File 'app/controllers/api/boards_controller.rb', line 58 def add_user raise ApiExceptions::AccessForbiddenError unless can_edit? user = User.find(params[:user_id]) board = Board.find(params[:id]) board.users << user render json: board end |
#create ⇒ Object
POST /boards
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'app/controllers/api/boards_controller.rb', line 22 def create raise ApiExceptions::AccessForbiddenError unless can_edit? board = Board.new(board_params) if board.save @parent.boards << board render json: board, status: :created else render json: board.errors, status: :unprocessable_entity end end |
#destroy ⇒ Object
DELETE /boards/1
49 50 51 52 53 54 55 |
# File 'app/controllers/api/boards_controller.rb', line 49 def destroy raise ApiExceptions::AccessForbiddenError unless can_edit? board = Board.find(params[:id]) board.destroy end |
#index ⇒ Object
GET /boards
11 12 13 |
# File 'app/controllers/api/boards_controller.rb', line 11 def index render json: @parent.boards end |
#remove_user ⇒ Object
DELETE /boards/1/users/34
69 70 71 72 73 74 75 76 77 |
# File 'app/controllers/api/boards_controller.rb', line 69 def remove_user raise ApiExceptions::AccessForbiddenError unless can_edit? user = User.find(params[:user_id]) board = Board.find(params[:id]) board.users.delete(user) render json: board end |
#show ⇒ Object
GET /boards/1
16 17 18 19 |
# File 'app/controllers/api/boards_controller.rb', line 16 def show board = Board.find(params[:id]) render json: board end |
#update ⇒ Object
PATCH/PUT /boards/1
36 37 38 39 40 41 42 43 44 45 46 |
# File 'app/controllers/api/boards_controller.rb', line 36 def update raise ApiExceptions::AccessForbiddenError unless can_edit? board = Board.find(params[:id]) if board.update(board_params) render json: board else render json: board.errors, status: :unprocessable_entity end end |