Class: Api::BoardsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/api/boards_controller.rb

Constant Summary collapse

ALLOWED_PARENT_CLASSES =
%w[peer_review application program space]

Instance Method Summary collapse

Methods included from Response

#json_response

Instance Method Details

#add_userObject

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

#createObject

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

#destroyObject

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

#indexObject

GET /boards



11
12
13
# File 'app/controllers/api/boards_controller.rb', line 11

def index
  render json: @parent.boards
end

#remove_userObject

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

#showObject

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

#updateObject

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