[#42552] added self link with query to unpaginated collection

pull/10703/head
Eric Schubert 2 years ago
parent 5a7aa2afba
commit c5a00561a3
No known key found for this signature in database
GPG Key ID: 1D346C019BD4BAA2
  1. 4
      docs/api/apiv3/paths/work_package_file_links.yml
  2. 10
      lib/api/decorators/unpaginated_collection.rb
  3. 11
      lib/api/v3/utilities/endpoints/index.rb
  4. 2
      modules/storages/app/models/queries/storages/file_links/filter/storage_filter.rb
  5. 7
      modules/storages/lib/open_project/storages/engine.rb

@ -136,9 +136,9 @@ get:
Accepts the same format as returned by the [queries](https://www.openproject.org/docs/api/endpoints/queries/)
endpoint. The following filters are supported:
- storage_id
- storage
required: false
example: '[{"storage_id":{"operator":"=","values":["42"]}}]'
example: '[{"storage":{"operator":"=","values":["42"]}}]'
schema:
type: string
responses:

@ -29,8 +29,8 @@
module API
module Decorators
class UnpaginatedCollection < ::API::Decorators::Collection
def initialize(models, self_link:, current_user:)
super(models, model_count(models), self_link: self_link, current_user: current_user)
def initialize(models, self_link:, current_user:, query: {})
super(models, model_count(models), self_link: make_self_link(self_link, query), current_user:)
end
def model_count(models)
@ -43,6 +43,12 @@ module API
models
end.count
end
private
def make_self_link(self_link_base, query)
"#{self_link_base}?#{query.to_query}"
end
end
end
end

@ -36,7 +36,7 @@ module API
scope: nil,
render_representer: nil,
self_path: api_name.underscore.pluralize)
super(model: model, api_name: api_name, scope: scope, render_representer: render_representer)
super(model:, api_name:, scope:, render_representer:)
self.self_path = self_path
end
@ -82,7 +82,7 @@ module API
if paginated_representer?
render_paginated_success(results, query, params, self_path)
else
render_unpaginated_success(results, self_path)
render_unpaginated_success(results, query, self_path)
end
end
@ -99,10 +99,13 @@ module API
current_user: User.current)
end
def render_unpaginated_success(results, self_path)
def render_unpaginated_success(results, query, self_path)
unpaginated_params = calculate_default_params(query).except(:offset, :pageSize)
render_representer
.new(results,
self_link: self_path,
query: unpaginated_params,
current_user: User.current)
end
@ -117,7 +120,7 @@ module API
return unless query.group_by
query.group_values.map do |group, count|
::API::Decorators::AggregationGroup.new(group, count, query: query, current_user: User.current)
::API::Decorators::AggregationGroup.new(group, count, query:, current_user: User.current)
end
end

@ -27,7 +27,7 @@
#++
module Queries::Storages::FileLinks::Filter
class StorageIdFilter < ::Queries::Filters::Base
class StorageFilter < ::Queries::Filters::Base
self.model = ::Storages::FileLink
def human_name

@ -94,12 +94,15 @@ module OpenProject::Storages
::Queries::Storages::WorkPackages::Filter::StorageIdFilter,
::Queries::Storages::WorkPackages::Filter::StorageUrlFilter,
::Queries::Storages::WorkPackages::Filter::LinkableToStorageIdFilter,
::Queries::Storages::WorkPackages::Filter::LinkableToStorageUrlFilter,
::Queries::Storages::FileLinks::Filter::StorageIdFilter
::Queries::Storages::WorkPackages::Filter::LinkableToStorageUrlFilter
].each do |filter|
filter filter
exclude filter
end
::Queries::Register.register(::Queries::Storages::FileLinks::FileLinkQuery) do
filter ::Queries::Storages::FileLinks::Filter::StorageFilter
end
end
end

Loading…
Cancel
Save