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

add setter for EntityRepresenterFactory

Klaus Zanders437c058631a6
diff --git a/modules/costs/lib/api/v3/time_entries/entity_representer_factory.rb b/modules/costs/lib/api/v3/time_entries/entity_representer_factory.rb
index e175c6f3939..f11cffc19eb 100644
--- a/modules/costs/lib/api/v3/time_entries/entity_representer_factory.rb
+++ b/modules/costs/lib/api/v3/time_entries/entity_representer_factory.rb
@@ -36,7 +36,7 @@ module API
##
# Create the appropriate subclass representer
- # for each principal entity
+ # for each Entity
def create(model, **args)
representer_class(model).create(model, **args)
end
@@ -91,6 +91,18 @@ module API
::API::V3::TimeEntries::EntityRepresenterFactory.create(instance, current_user:)
}
end
+
+ def create_setter_lambda(name, property_name: name, namespaces: %i(work_packages meetings))
+ ->(fragment:, **) {
+ ::API::Decorators::LinkObject
+ .new(represented,
+ property_name:,
+ namespace: namespaces,
+ getter: :"#{name}_id",
+ setter: :"#{name}_id=")
+ .from_hash(fragment)
+ }
+ end
end
end
end
diff --git a/modules/costs/lib/api/v3/time_entries/time_entry_representer.rb b/modules/costs/lib/api/v3/time_entries/time_entry_representer.rb
index eb02ba53f82..d0074315ea8 100644
--- a/modules/costs/lib/api/v3/time_entries/time_entry_representer.rb
+++ b/modules/costs/lib/api/v3/time_entries/time_entry_representer.rb
@@ -95,6 +95,7 @@ module API
associated_resource :entity,
getter: ::API::V3::TimeEntries::EntityRepresenterFactory.create_getter_lambda(:entity),
+ setter: ::API::V3::TimeEntries::EntityRepresenterFactory.create_setter_lambda(:entity),
link: ::API::V3::TimeEntries::EntityRepresenterFactory.create_link_lambda(:entity)
# TODO: DEPRECATED!