diff options
author | Patrick Derichs <pderichs@gitlab.com> | 2019-07-05 12:50:20 +0200 |
---|---|---|
committer | Patrick Derichs <pderichs@gitlab.com> | 2019-07-16 16:18:16 +0200 |
commit | 1ebef4aae55adb5e17a76b92aea74467e49130bf (patch) | |
tree | b39ccf8b45017903a4bad4438cad3518e6c41c0e /app | |
parent | 46fb73a372621918fae77c0d338d9a42a13071fd (diff) | |
download | gitlab-ce-1ebef4aae55adb5e17a76b92aea74467e49130bf.tar.gz |
Add result to MoveService#execute_multiple
It adds a hash response which includes
the count, success state and the moved
issues itself so the caller has additional
information about the result of the
process.
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/boards/issues_controller.rb | 7 | ||||
-rw-r--r-- | app/services/boards/issues/move_service.rb | 39 |
2 files changed, 34 insertions, 12 deletions
diff --git a/app/controllers/boards/issues_controller.rb b/app/controllers/boards/issues_controller.rb index 353a9806fd1..90528f75ffd 100644 --- a/app/controllers/boards/issues_controller.rb +++ b/app/controllers/boards/issues_controller.rb @@ -58,11 +58,8 @@ module Boards service = Boards::Issues::MoveService.new(board_parent, current_user, move_params(true)) issues = Issue.find(params[:ids]) - if service.execute_multiple(issues) - head :ok - else - head :unprocessable_entity - end + + render json: service.execute_multiple(issues) end def update diff --git a/app/services/boards/issues/move_service.rb b/app/services/boards/issues/move_service.rb index 755d723b9a0..00ce27db7c8 100644 --- a/app/services/boards/issues/move_service.rb +++ b/app/services/boards/issues/move_service.rb @@ -11,26 +11,51 @@ module Boards end def execute_multiple(issues) - return false if issues.empty? + return execute_multiple_empty_result if issues.empty? + handled_issues = [] last_inserted_issue_id = nil - issues.map do |issue| + count = issues.each.inject(0) do |moved_count, issue| issue_modification_params = issue_params(issue) - next if issue_modification_params.empty? + next moved_count if issue_modification_params.empty? if last_inserted_issue_id - issue_modification_params[:move_between_ids] = move_between_ids({ move_after_id: nil, move_before_id: last_inserted_issue_id }) + issue_modification_params[:move_between_ids] = move_below(last_inserted_issue_id) end last_inserted_issue_id = issue.id - move_single_issue(issue, issue_modification_params) - end.all? + handled_issue = move_single_issue(issue, issue_modification_params) + handled_issues << present_issue_entity(handled_issue) if handled_issue + handled_issue && handled_issue.valid? ? moved_count + 1 : moved_count + end + + { + count: count, + success: count == issues.size, + issues: handled_issues + } end private + def present_issue_entity(issue) + ::API::Entities::Issue.represent(issue) + end + + def execute_multiple_empty_result + @execute_multiple_empty_result ||= { + count: 0, + success: false, + issues: [] + } + end + + def move_below(id) + move_between_ids({ move_after_id: nil, move_before_id: id }) + end + def move_single_issue(issue, issue_modification_params) - return false unless can?(current_user, :update_issue, issue) + return unless can?(current_user, :update_issue, issue) update(issue, issue_modification_params) end |