diff options
author | Felipe Artur <felipefac@gmail.com> | 2017-08-28 18:56:49 -0300 |
---|---|---|
committer | Felipe Artur <felipefac@gmail.com> | 2017-08-28 18:56:49 -0300 |
commit | f2a43ff5b7eec188ffc470649bf40d268cbdce2a (patch) | |
tree | f9a59f5d83d883c482c9ebfe811580a0fc8f6be6 /app/controllers/boards/lists_controller.rb | |
parent | 5f88660a3f5d9f0de0109a3da46e81ea9024c677 (diff) | |
download | gitlab-ce-f2a43ff5b7eec188ffc470649bf40d268cbdce2a.tar.gz |
Group boards CE backport
Diffstat (limited to 'app/controllers/boards/lists_controller.rb')
-rw-r--r-- | app/controllers/boards/lists_controller.rb | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/app/controllers/boards/lists_controller.rb b/app/controllers/boards/lists_controller.rb new file mode 100644 index 00000000000..a4ed37dab31 --- /dev/null +++ b/app/controllers/boards/lists_controller.rb @@ -0,0 +1,74 @@ +module Boards + class ListsController < Boards::ApplicationController + include BoardsResponses + + before_action :authorize_admin_list, only: [:create, :update, :destroy, :generate] + before_action :authorize_read_list, only: [:index] + + def index + lists = Boards::Lists::ListService.new(board.parent, current_user).execute(board) + + render json: serialize_as_json(lists) + end + + def create + list = Boards::Lists::CreateService.new(board.parent, current_user, list_params).execute(board) + + if list.valid? + render json: serialize_as_json(list) + else + render json: list.errors, status: :unprocessable_entity + end + end + + def update + list = board.lists.movable.find(params[:id]) + service = Boards::Lists::MoveService.new(board_parent, current_user, move_params) + + if service.execute(list) + head :ok + else + head :unprocessable_entity + end + end + + def destroy + list = board.lists.destroyable.find(params[:id]) + service = Boards::Lists::DestroyService.new(board_parent, current_user) + + if service.execute(list) + head :ok + else + head :unprocessable_entity + end + end + + def generate + service = Boards::Lists::GenerateService.new(board_parent, current_user) + + if service.execute(board) + render json: serialize_as_json(board.lists.movable) + else + head :unprocessable_entity + end + end + + private + + def list_params + params.require(:list).permit(:label_id) + end + + def move_params + params.require(:list).permit(:position) + end + + def serialize_as_json(resource) + resource.as_json( + only: [:id, :list_type, :position], + methods: [:title], + label: true + ) + end + end +end |