Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

refactor: use methods from ServiceResult instead of computing compound results

Christophe Bliard2ec5db6e89a5
diff --git a/lib/api/utilities/endpoints/modify.rb b/lib/api/utilities/endpoints/modify.rb
index 97afeea6ccb..2187aeafffa 100644
--- a/lib/api/utilities/endpoints/modify.rb
+++ b/lib/api/utilities/endpoints/modify.rb
@@ -36,12 +36,6 @@ module API
end
end
- protected
-
- def build_error_from_result(result)
- ActiveModel::Errors.new result
- end
-
private
def present_success(_request, _call)
@@ -62,7 +56,7 @@ module API
end
def merge_dependent_errors(call)
- errors = build_error_from_result(call.result)
+ errors = ActiveModel::Errors.new call.all_results.first
call.dependent_results.each do |dr|
dr.errors.full_messages.each do |full_message|
diff --git a/modules/storages/lib/api/v3/file_links/create_endpoint.rb b/modules/storages/lib/api/v3/file_links/create_endpoint.rb
index de683e3dc11..c6f50017f27 100644
--- a/modules/storages/lib/api/v3/file_links/create_endpoint.rb
+++ b/modules/storages/lib/api/v3/file_links/create_endpoint.rb
@@ -46,32 +46,25 @@ module API::V3::FileLinks
# call is done by calling the `super` method. Results are aggregated in
# global_result using the `add_dependent!` method.
def process(request, params_elements)
- global_result = ServiceResult.new(
- success: true,
- result: []
- )
+ global_result = ServiceResult.new(success: true)
params_elements.each do |params|
+ # call the default API::Utilities::Endpoints::Create#process
+ # implementation for each of the params_element array
one_result = super(request, params)
+ # merge service result in one
global_result.add_dependent!(one_result)
- global_result.result << one_result.result
end
global_result
end
def present_success(request, service_call)
render_representer.create(
- service_call.result,
+ service_call.all_results,
self_link: request.api_v3_paths.file_links(request.work_package.id),
current_user: request.current_user
)
end
- protected
-
- def build_error_from_result(result)
- ActiveModel::Errors.new result.first
- end
-
private
def params_modifier